在開發中使用的版本控制器時git , 每次使用命令"git pull"從服務器獲得最新代碼時,都需要輸入用戶名和密碼,這樣浪費了大量的時間和熱情,在此背景下,本文在網上找到解決版本,在此做一個總結,已做留念。
1 查看項目的存放地址
首先看下每次輸入用戶名和密碼的提示。項目存放在以下地址:
http://192.9.100.193
2 創建 Git 存儲用戶名和密碼
在%HOME%目錄中,一般是 c:/users/{當前用戶名} 目錄下。文件名為.git-credentials,由於在Window中不允許直接創建以"."開頭的文件,所以需要借助git bash進行,打開git bash客戶端,進行%HOME%目錄,然后用文本編輯器打開文件 .git-credentials,輸入以下內容:
touch .git-credentials vim .git-credentials http://{用戶名}:{密碼}@192.9.100.193
3 添加 Git Config內容
進入git bash終端, 輸入如下命令:
git config --global credential.helper store
執行完后查看%HOME%目錄下的.gitconfig文件,會多了一項。
[credential]
helper = store
重新開啟git bash會發現git push時不用再輸入用戶名和密碼。
注意:
如果不能提交代碼到git服務器,需要將帳號綁定到git工具上。若不綁定,當你執行git commit 是報如下錯誤。
*** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository.
需要執行 git config --global 命令,全局配置用戶的姓名和郵箱,就可以提交git 代碼了。
git config --global user.email {用戶郵箱} git config --global user.name {用戶賬號}
