平時我們在使用git命令時,如果使用http方式拉取代碼每次都需要使用填寫用戶名和密碼谣沸,非常的麻煩。
如何才能繞過每次繁瑣的填充?
如果想要繞過git的交互方式笋颤,首先需要了解git的密碼存儲機制乳附。
git使用的使用是一種名叫[credential helper]的工具來完成用戶名密碼存儲的。
可以通過git config --global credential.helper
命令來查看本機使用的哪種方式,或者查看用戶目錄下的.gitconfig
文件
可以通過命令git config --global credential.helper cache/store/manager-core
設置密碼存儲方式赋除。
以下是[credential helper]的幾種存儲方式:
①cache:cache 將憑據在內存中進行短時間的緩存阱缓。使用的比較少。
②store:store通過明文的方式將用戶名和密碼保存到用戶目錄下举农,可以使用記事本直接打開:
如果使用這種方式荆针,可以通過修改.git-credentials文件的方式繞過填充和密碼修改,形如:https://username:password@gitee.com颁糟。如果是首次使用需要創(chuàng)建該文件航背。
git config --global credential.helper store --file=xxxxx
可以設置讀取.git-credentials文件的位置。
③manager-core:如果是windows機器滚停,可以使用名為windows憑據的[credential helper]工具沃粗,這是一種windows自帶的密碼管理器,非常適合存儲git用戶名和密碼键畴。如下圖:
如果想以這種方式存儲git的用戶名和密碼最盅,就需要使用cmd命令了
//刪除某個windows憑據 cmdkey /delete:git:https://gitee.com //添加某個windows憑據 cmdkey /generic:git:http://gitee.com /user:%username% /password:%password%
note:使用之前需要先查看[credential helper]以哪種方式存儲
此外[credential helper]工具還支持配置多種存儲方式。當查找特定服務器的憑證時起惕,git 會按順序查詢涡贱,并且在找到第一個符合條件的機器時就返回。配置如下:
[credential]
helper = manager-core
helper = store --file c:\\.git-credentials
helper = cache --timeout 30000