linux
- 在~/下, touch 創(chuàng)建文件
.git-credentials
, 用 vim 編輯此文件爬迟,輸入內(nèi)容格式:
touch .git-credentials
vim .git-credentials
https://{username}:{password}@github.com
- 在終端下執(zhí)行
git config --global credential.helper store
- 可以看到
~/.gitconfig
文件密幔,會多了一項:
[credential]
helper = store
windows
方法一
- 創(chuàng)建文件存儲
git
用戶名和密碼
在%HOME%
目錄中涣澡,一般為
C:\users\用戶名
文件名為
.git-credentials
由于在 Window 中不允許直接創(chuàng)建以"."開頭的文件闽撤,所以需要借助 git bash 進行舱呻,打開 git bash 客戶端次企,進行%HOME%
目錄怯晕,然后用 touch 創(chuàng)建文件 .git-credentials
touch .git-credentials
用 vim 編輯此文件,輸入內(nèi)容格式:
vim .git-credentials
https://{username}:{password}@github.com
- 添加 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 時不用再輸入用戶名和密碼
方法二
- 添加環(huán)境變量
在 windows 中添加一個HOME
環(huán)境變量,
變量名:HOME
變量值:%USERPROFILE%
- 創(chuàng)建 git 用戶名和密碼存儲文件
進入%HOME%
目錄,新建一個名為\_netrc
的文件吧凉,文件中內(nèi)容格式如下:
machine {git account name}.github.com
login your-usernmae
password your-password
重新打開 git bash
即可隧出,無需再輸入用戶名和密碼