1. 程式人生 > >git命令列pull,push避免重複輸入使用者名稱密碼

git命令列pull,push避免重複輸入使用者名稱密碼

相信大家一定遇到過git和開發工具結合不是很好的情況,pull不下來,push不上去。But we are coder rather than  coolie.  (Just be a Joke!)  這時,git命令列就因其很好的容錯提交方便了我們的開發。以下是命令列經常遇到的一問題。

   git避免重複輸入使用者名稱密碼。

1、在git bash命令列中輸入   echo $HOME  檢視git home路徑。

2、進入home對應的路徑中。

touch .git-credentials    建立.git-credentials

vim .git-credentials 編輯

在./git-credentials中加入以下文字(此處文字URL可以固定寫成這樣,如果你的URL和這個不一樣,執行完以下操作之後只需要在命令列輸入一次

使用者名稱密碼會自動把你所使用的URL追加進去),username 和password分別代表使用者名稱密碼

https://username:[email protected]

git config --global credential.helper store

這是檢視home路徑中的.gitconfig,會在之前

[user]
name =
**********

email=***********

的基礎上多出

[credential]
helper = stor
e

3、在命令列正常執行pull ,push,如果是在以上操作完之後第一次執行向任何URL的pull push,需要輸入一次使用者名稱密碼,以後不再需要輸入。

第一次向新的URL輸入使用者名稱密碼之後會發現 .git-credentials中追加了類似 https://username:[email protected]的內容。

Game Over !