我曾經(jīng)切換過一次github賬號, 似乎還更改過一次github賬號的密碼, 然后呢?
然后就是每次向github提交代碼時都要輸入用戶名密碼(猜測是由于上述原因?qū)е?,
每次都是啊, 這也忒麻煩了, 于是就想辦法解決這個問題, 經(jīng)過一番查找, 終于找到一個解決辦法, 分享之, 與君共勉 !!
==============
解決方案:
- 在你的用戶目錄下新建一個文本文件, 名曰
.git-credentials
用戶目錄:- windows:
C:/Users/username
- mac os x:
/Users/username
- linux:
/home/username
- windows:
- 在上一步創(chuàng)建的文件中輸入一下內(nèi)容:
https:{username}:{password}@github.com
當然上述{username}和{password}要換成你的github的賬號名和密碼 - 修改git配置
執(zhí)行命令git config --global credential.helper store
上述命令會在~/.gitconfig
文件末尾添加如下配置:[credential] helper = store
經(jīng)過上述三步配置之后, 你push代碼到github時, 便無需再輸入用戶名密碼了~~
=================
續(xù)集......
后來發(fā)現(xiàn), 不用上面三步這么麻煩, 簡化流程如下:
- 在命令行輸入命令:
git config --global credential.helper store
? 這一步會在用戶目錄下的.gitconfig文件最后添加:
[credential]
helper = store
- 現(xiàn)在push你的代碼 (
git push
), 這時會讓你輸入用戶名密碼, 這一步輸入的用戶名密碼會被記住, 下次再push代碼時就不用輸入用戶名密碼啦!
?這一步會在用戶目錄下生成文件.git-credential
記錄用戶名密碼的信息.
?git config --global
命令實際上在操作用戶目錄下的.gitconfig
文件, 我們cat一下此文件(cat .gitconfig
), 其內(nèi)容如下:
[user]
name = alice
email = alice@aol.com
[push]
default = simple
[credential]
helper = store
git config --global user.email "alice@aol.com"
操作的就是上面的email
git config --global push.default matching
操作的就是上面的push段中的default字段
git config --global credential.helper store
操作的就是上面最后一行的值