github のプライベートリポジトリで「ターミナルプロンプトが無効です」というエラーが発生する 質問する

github のプライベートリポジトリで「ターミナルプロンプトが無効です」というエラーが発生する 質問する

ブラウザから Github UI を使用してプライベート リポジトリ examplesite/myprivaterepo を作成しました。

次に、go ディレクトリ (デスクトップ上) に移動してクローンを作成しました。

$ cd $GOPATH
$ go get github.com/examplesite/myprivaterepo

ここまでは順調です。scheduler.go ファイルを作成し、リポジトリに追加してプッシュしました。

$ vim scheduler.go
$ git add scheduler.go
$ git commit
$ git push

すべて問題ありません。しかし、クリーンなラップトップでリポジトリをクローンしようとすると、エラーが発生しました。

# Now on laptop, which doesn't yet know about the repo
$ cd $GOPATH
$ go get github.com/examplesite/myprivaterepo
# At this point it should ask for my user ID and password ,right? But it doesn't.
# Instead, this error occurs:
cd .; git clone https://github.com/examplesite/myprivaterepo /Users/tom/go/src/github.com/examplesite/myprivaterepo
Cloning into '/Users/tom/go/src/github.com/examplesite/myprivaterepo'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/examplesite/myprivaterepo: exit status 128

なぜ私のラップトップは自分のリポジトリを嫌うのでしょうか。また、その運命を受け入れるにはどうしたらよいでしょうか。ありがとうございます。

ベストアンサー1

これは非常に役立ち、問題を解決しました。このコマンドにより、2FA が機能するようになります (ユーザー名とパスワードを入力する手間が省けます)。

Githubの場合:

git config --global --add url."[email protected]:".insteadOf "https://github.com/"

Gitlabの場合:

git config --global --add url."[email protected]:".insteadOf "https://gitlab.com/"

ソース:http://albertech.blogspot.com/2016/11/fix-git-error-could-not-read-username.html

2FA を使用していない場合でも、SSH を使用すれば機能します。

結果は.gitconfig次のようになります:

[url "[email protected]:"]
    insteadOf = https://github.com/

おすすめ記事