問題
在下載公司內部的包時,出現如下提示:
go get: module example.com/somepkg/common: git ls-remote -q origin in /somepath/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: exit status 128:
fatal: could not read Username for 'https://xxx.example.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
原因
查詢了下必應,大致原因是,下載包時,沒有用戶名和密碼,導致沒有權限,因此需要啟用彈窗,以便輸入用戶名和密碼。
解決
設置環境變量:GIT_TERMINAL_PROMPT 為 1
也可以在你 go get example.com/some/pkg 時,直接設置:GIT_TERMINAL_PROMPT=1 go get -u example.com/path/yourpkg
同時為了能在以后不用再輸入用戶名和密碼,可以設定儲存密碼:
git config --global credential.helper store