本文翻译自:How to save username and password in Git?
I want to use a push and pull automatically in GitExtension , without entering my user and password in a prompt, every time. 我想在GitExtension中自动使用推拉操作 ,而不必每次都在提示中输入用户名和密码。
So how can I save my credentials in GIT ? 那么如何将我的凭据保存在GIT中呢?
#1楼
参考:https://stackoom.com/question/2QoLq/如何在Git中保存用户名和密码
#2楼
Run 跑
1 | git config --global credential.helper store |
then 然后
1 | git pull |
provide a username and password and those details will then be remembered later. 提供用户名和密码,这些详细信息将在以后被记住。 The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext. 凭据存储在磁盘上的文件中,磁盘权限为“仅用户可读/可写”,但仍为纯文本格式。
If you want to change the password later 如果您以后想要更改密码
1 | git pull |
Will fail, because the password is incorrect, git then removes the offending user+password from the
1 | git pull |
to provide a new password so it works as earlier. 提供一个新密码,使其可以更早地工作。
#3楼
You can use the
1 | git config --global credential.helper store |
When running this command, the first time you pull or push from the remote repository, you'll get asked about the username and password. 运行此命令时,第一次从远程存储库中拉出或推送时,系统会询问您用户名和密码。
Afterwards, for consequent communications with the remote repository you don't have to provide the username and password. 之后,为了与远程存储库进行后续通信,您无需提供用户名和密码。
The storage format is a
Also, you can use other helpers for the
1 | git config credential.helper cache <timeout> |
which takes an optional
WARNING : If you use this method, your git account passwords will be saved in
If this is undesirable to you, use an
#4楼
Turn on the credential helper so that Git will save your password in memory for some time: 打开凭据助手,以便Git将您的密码保存在内存中一段时间??:
In Terminal, enter the following: 在终端中,输入以下内容:
1 2 | # Set git to use the credential memory cache git config --global credential.helper cache |
By default, Git will cache your password for 15 minutes. 默认情况下,Git会将您的密码缓存15分钟。
To change the default password cache timeout, enter the following: 要更改默认密码缓存超时,请输入以下内容:
1 2 | # Set the cache to timeout after 1 hour (setting is in seconds) git config --global credential.helper 'cache --timeout=3600' |
From GitHub Help 从GitHub帮助
#5楼
You will be more secure if you use SSH authentication than username/password authentication. 如果您使用SSH身份验证,则比用户名/密码身份验证更安全。
If you are using a Mac, SSH client authentication is integrated into the MacOS keychain. 如果您使用的是Mac,则SSH客户端身份验证已集成到MacOS钥匙串中。 Once you have created an SSH key, type into your terminal: 创建SSH密钥后,在终端中输入:
1 | ssh-add -K ~/.ssh/id_rsa |
This will add the SSH private key to the MacOS keychain. 这会将SSH私钥添加到MacOS钥匙串中。 The git client will use ssh when it connects to the remote server. git客户端连接到远程服务器时将使用ssh。 As long as you have registered your ssh public key with the server, you will be fine. 只要您在服务器上注册了ssh公钥,就可以了。
#6楼
You can edit the
1 | sudo nano ~/.gitconfig |
Which should already have 哪个应该已经有
1 2 3 |
You should add at the bottom of this file. 您应该在此文件的底部添加。
1 2 | [credential] helper = store |
The reason I recommend this option is cause it is global and if at any point you need to remove the option you know where to go and change it. 我之所以建议使用此选项,是因为它是全局的,如果您随时需要删除该选项,则知道该去哪里进行更改。
ONLY USE THIS OPTION IN YOU PERSONAL COMPUTER. 仅在个人计算机中使用此选项。
Then when you pull | 然后当你拉| clone| 克隆| enter you git password, in general, the password will be saved in
1 | https://GITUSER:[email protected] |
WHERE DOMAIN.XXX COULD BE GITHUB.COM | DOMAIN.XXX可能位于GITHUB.COM | BITBUCKET.ORG | BITBUCKET.ORG | OTHER 其他
See Docs 查看文件