1. 程式人生 > >解決`向github提交代碼是老要輸入用戶名密碼`

解決`向github提交代碼是老要輸入用戶名密碼`

信息 更改 文本 就是 === AC helper 作用 linux

我曾經切換過一次github賬號, 似乎還更改過一次github賬號的密碼, 然後呢?
然後就是每次向github提交代碼時都要輸入用戶名密碼(猜測是由於上述原因導致),
每次都是啊, 這也忒麻煩了, 於是就想辦法解決這個問題, 經過一番查找, 終於找到一個解決辦法, 分享之, 與君共勉 !!

==============

解決方案:

在你的用戶目錄下新建一個文本文件, 名曰.git-credentials
用戶目錄:
windows: C:/Users/username
mac os x: /Users/username
linux: /home/username
在上一步創建的文件中輸入一下內容:
https:{username}:{password}@github.com
當然上述{username}和{password}要換成你的github的賬號名和密碼
修改git配置
執行命令git config --global credential.helper store
上述命令會在~/.gitconfig文件末尾添加如下配置:
[credential]
helper = store
經過上述三步配置之後, 你push代碼到github時, 便無需再輸入用戶名密碼了~~

=================
續集......
後來發現, 不用上面三步這麽麻煩, 簡化流程如下:

在命令行輸入命令:
git config --global credential.helper store
? 這一步會在用戶目錄下的.gitconfig文件最後添加:
[credential]
helper = store
現在push你的代碼 (git push), 這時會讓你輸入用戶名密碼, 這一步輸入的用戶名密碼會被記住, 下次再push代碼時就不用輸入用戶名密碼啦!
?這一步會在用戶目錄下生成文件.git-credential記錄用戶名密碼的信息.
? git config --global 命令實際上在操作用戶目錄下的.gitconfig文件, 我們cat一下此文件(cat .gitconfig), 其內容如下:
[user]
name = alice
email = [email protected]
[push]
default = simple
[credential]
helper = store
git config --global user.email "[email protected]" 操作的就是上面的email
git config --global push.default matching 操作的就是上面的push段中的default字段
git config --global credential.helper store 操作的就是上面最後一行的值

原文信息

作者:元亨利貞o
鏈接:https://www.jianshu.com/p/81ae6e77ff47
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請註明出處。

解決`向github提交代碼是老要輸入用戶名密碼`