解決方案:
方案一:
在你的用戶目錄下新建一個文本文件.git-credentials
Windows:C:/Users/username
Mac OS X: /Users/username
Linux: /home/username
注意:鼠標右鍵新建文件重複命名是成功不了的,需要藉助Sublime等IDE工具來創建文件。
.git-credentials在文件中輸入以下內容:
https:{username}:{password}@github.com
{username}和{password}是你的github的賬號和密碼
修改git配置
執行命令:
git config --global credential.helper store
上述命令會在.gitconfig文件(.gitconfig與.git-credentials在同目錄下)末尾添加如下配置:
圖片描述
經過上述三步配置之後, 你push代碼到github時, 便無需再輸入用戶名密碼了
方案二:
在命令行輸入命令:
git config --global credential.helper store
這一步會在用戶目錄下的.gitconfig文件最後添加:
[credential]
helper = store
push 代碼
push你的代碼 (git push), 這時會讓你輸入用戶名和密碼, 這一步輸入的用戶名密碼會被記住, 下次再push代碼時就不用輸入用戶名密碼!這一步會在用戶目錄下生成文件.git-credential記錄用戶名密碼的信息。
總結:
方案一與方案二都是創建.git-credential文件並寫入用戶信息,一個是手動創建,一個命令創建。