1.方法一
1.1 創(chuàng)建文件存儲GIT用戶名和密碼
在%HOME%目錄中脖旱,一般為C:\users\Administrator盼玄,也可以是你自己創(chuàng)建的系統(tǒng)用戶名目錄娩怎,反正都在C:\users\中帕识。文件名為.git-credentials,由于在Window中不允許直接創(chuàng)建以"."開頭的文件泛粹,所以需要借助git bash進行,打開git bash客戶端肮疗,進行%HOME%目錄晶姊,然后用touch創(chuàng)建文件 .git-credentials, 用vim編輯此文件,輸入內(nèi)容格式:
touch .git-credentials
vim .git-credentials
https://{username}:{password}@github.com
1.2 添加Git Config 內(nèi)容
進入git bash終端伪货, 輸入如下命令:
git config --global credential.helper store
執(zhí)行完后查看%HOME%目錄下的.gitconfig文件们衙,會多了一項:
[credential] helper = store
重新開啟git bash會發(fā)現(xiàn)git push時不用再輸入用戶名和密碼
2.方法二
2.1 添加環(huán)境變量
在windows中添加一個HOME環(huán)境變量,變量名:HOME,變量值: %USERPROFILE%
2.2 創(chuàng)建git用戶名和密碼存儲文件
進入%HOME%目錄碱呼,新建一個名為"_netrc"的文件蒙挑,文件中內(nèi)容格式如下:
machine {git account name}.github.com
login your-username
password your-password
重新打開git bash即可,無需再輸入用戶名和密碼