LoginSignup
2
3

More than 3 years have passed since last update.

Google ColaboratoryからGitHubにpushしたらcould not read Username for 'https://github.com': No such file or directoryでpushできない件について

Posted at

はじめに

Google Colablatoryの有料版を契約したので、とりあえず記事の内容を検証するのに頻繁に使っており、Git管理したいとリポジトリを作りpushしたのですが、エラーがでたのでColabのpushの流れも含めて紹介します。

問題

test_colabというパブリックなリポジトリをGitHubで作成して、以下のコマンドを実行しました。

!git remote add origin  https://github.com/jinwatanabe/test_colab.git
!git push origin -u main

すると、以下のようなエラーが発生しました。

fatal: could not read Username for 'https://github.com': No such file or directory

解決方法

!git remote add originに続く、リポジトリのHTTPSを、
https://{username}:{password}@github.com/{username}/project.gitのように変更します。
usernameとpasswordはGitHubの自分のアカウントの情報になります。

ユーザー名:jinwatanabe
パスワード: password
の場合は以下のコマンドになります。

# git remote add origin https://{username}:{password}@github.com/{username}/project.git
!git clone https://jinwatanabe:password@github.com/jinwatanabe/test_colab.git
!git push -u origin main

これでうまくいきました。

Colabでgit pushまでのコマンド

pushまでのコマンドをまとめておきます。

!git init
!git config --global user.email "your email"
!git config --global user.name "your user name"
!git add .
!git commit -m "your commit message"
!git branch -M main
!git remote add origin https://{username}:{password}@github.com/{username}/project.git

# ここでfatal: remote origin already exists. とでたら以下のコマンド
# !git remote rm origin
# !git remote add origin https://{username}:{password}@github.com/{username}/project.git

!git push -u origin main

さいごに

git remote rm originは毎回調べてる気がしたので、そろそろ覚えたいところです。
Colab便利ですが、環境構築の手間を忘れてしまうので、実際のローカル環境で同じコードを動かそうとしたときにライブラリが入っていなかったりでエラーをたくさんはいてしまいます。便利ですが悩みどころです。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3