首先命令行操作結果如下:
root@zhiren-PowerEdge-T110-II:/zrun# git clone https://git.coding.net/xxxxxxxx/xxxx.git
正克隆到 'anbu'...
remote: Coding.net Tips : [You have no permission to access this repo.]
fatal: unable to access 'https://git.coding.net/xxxxxxxx/xxxx.git/': The requested URL returned error: 403
起初完全不知道哪里出了問題。后來到處查閱,發現原因:git 客戶端緩存了錯誤的密碼。
問題起源:
https方式每次都要輸入密碼,按照如下設置即可輸入一次就不用再手輸入密碼的困擾而且又享受https帶來的極速
設置記住密碼(默認15分鍾):
git config --global credential.helper cache
如果想自己設置時間,可以這樣做:
git config credential.helper 'cache --timeout=3600'
這樣就設置一個小時之后失效
長期存儲密碼:
git config --global credential.helper store
增加遠程地址的時候帶上密碼也是可以的。(推薦)
http://yourname:password@git.oschina.net/name/project.git
真是后悔,圖一時痛快,忽略了寶貴的“推薦”二字。
git config --global credential.helper store該命令可以將用戶名和密碼長期全局地長期地存儲在客戶端(實際是客戶端所在電腦,並非git的任何目錄下,也就是說,即使重裝git,改密碼也存在。),注意是全局地。
原作者不推薦的原因正是這個。因為,這里保存的賬號和密碼會自動應用到每一個git clone指令,如果想要克隆的不是該賬號下的項目,就只會得到403錯誤。
下路給出正解:
方法一:
增加遠程地址的時候帶上密碼也是可以的。(推薦)
http://yourname:password@git.oschina.net/name/project.git
這種方式會把改賬號和密碼也添加到~/.git-credentials。
方法二:
運行命令:rm ~/.git-credentials,刪掉git config --global credential.helper store保存的賬號和密碼。回到每次輸入用戶名和密碼。
~/.git-credentials
勿以善小而不為——想要掌握一門技術或者一種規范,啟用了一個點,就成功了一半。