我把我的工作推到一个远程git存储库。

每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?


当前回答

运行下面的命令为我解决了这个问题。

git config --global credential.helper wincred

请参考以下github文档:

https://help.github.com/articles/caching-your-github-password-in-git/

其他回答

我使用的是https链接(https://github.com/org/repo.git) 而不是SSH链接;

git@github.com:org/repo.git  

转换为我解决了这个问题!

我用了帕维尔建议的答案,它对我很有效。我的区别是这样做,而我是这样添加远程:git远程添加(别名)https://(name:password)@github.com/(the远程地址).git

在我的例子中,使用SSH,在将公钥添加到GitHub之后,然后将远程设置为git@github.com/username/reponame.git之类的东西,以及在本地永久添加私钥。本地命令如下:

ssh-add

ssh-add - k

我想有些人可能忽略了后一步。

无限期保存

您可以使用git-credential-store

git config credential.helper store

在文件系统中保存未加密的密码:

使用此助手将在磁盘上存储未加密的密码,仅受文件系统权限的保护。如果这不是一种可以接受的安全折衷,请尝试git-凭据-缓存,或寻找与操作系统提供的安全存储集成的帮助器。

使用暂停

使用git-credential-cache,默认保存密码15分钟。

git config credential.helper cache

要设置不同的超时,使用——timeout(这里是5分钟)

git config credential.helper 'cache --timeout=300'

安全无限保存(OS X和Windows)

If you’re using a Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. This method stores the credentials on disk, and they never expire, but they’re encrypted with the same system that stores HTTPS certificates and Safari auto-fills. Running the following on the command line will enable this feature: git config --global credential.helper osxkeychain. You'll need to store the credentials in the Keychain using the Keychain app as well. If you’re using Windows, you can install a helper called “Git Credential Manager for Windows.” This is similar to the “osxkeychain” helper described above, but uses the Windows Credential Store to control sensitive information. It can be found at https://github.com/Microsoft/Git-Credential-Manager-for-Windows. [emphases mine]

如果您已经设置了SSH密钥,并且仍然得到密码提示,请确保表单中有您的回购URL

git+ssh://git@github.com/username/reponame.git

而不是

https://github.com/username/reponame.git

要查看您的回购URL,运行:

git remote show origin

你可以像这样用git remote set-url修改URL:

git remote set-url origin git+ssh://git@github.com/username/reponame.git