解決方案:方案一:
在你的用戶目錄下新建一個文本文件.git-credentials
Windows
:C:/Users/username
Mac OS X
: /Users/username
Linux
: /home/username
注意:鼠標右鍵新建文件重復命名
是成功不了的庶灿,需要借助Sublime
等IDE
工具來創(chuàng)建文件。
.git-credentials
在文件中輸入以下內(nèi)容:
https:{username}:{password}@github.com
{username}
和{password}
是你的github
的賬號
和密碼
修改git
配置執(zhí)行命令:
git config --global credential.helper store
上述命令會在.gitconfig
文件(.gitconfig
與.git-credentials
在同目錄下)末尾添加如下配置:
經(jīng)過上述三步配置之后, 你push代碼
到github時, 便無需再輸入用戶名密碼
了
方案二:
在命令行輸入命令:
git config --global credential.helper store
這一步會在用戶目錄下的.gitconfig
文件最后添加:
[credential] helper = store
push 代碼push
你的代碼 (git push
), 這時會讓你輸入用戶名
和密碼
, 這一步輸入的用戶名密碼會被記住
, 下次再push代碼時就不用輸入用戶名密碼!這一步會在用戶目錄下生成文件.git-credential
記錄用戶名密碼的信息契吉。
總結:方案一
與方案二
都是創(chuàng)建.git-credential
文件并寫入用戶信息跳仿,一個是手動創(chuàng)建,一個命令創(chuàng)建捐晶。
方案三:
原因是使用了https方式 push
在termail里邊 輸入 Git remote -v
可以看到形如一下的返回結果
origin https://github.com/yuquan0821/demo.git (fetch)
origin https://github.com/yuquan0821/demo.git (push)
下面把它換成ssh方式的菲语。
- git remote rm origin
- git remote add origin git@github.com:yuquan0821/demo.git
- git push origin