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

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


当前回答

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

ssh-add

ssh-add - k

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

其他回答

只需使用——repo选项git push命令。是这样的:

$ git push --repo https://name:password@bitbucket.org/name/repo.git

如果您已经设置了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

我在Windows上的解决方案:

右键单击目录,并选择“Git Bash Here”。 ssh-keygen -t rsa(所有值都按enter键) 您的公钥已保存在/c/Users/<your_user_name_here>/.ssh/id_rsa.pub 从指定文件复制公钥。 去你的GitHub配置文件=>设置=> SSH和GPG密钥=>新的SSH密钥=>粘贴您的SSH密钥=>保存

使用Git存储库进行永久身份验证,

运行以下命令启用凭据缓存。

$ git config credential.helper store
$ git push https://github.com/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

Use还应该指定缓存过期,

git config --global credential.helper 'cache --timeout 7200'

启用凭据缓存后,它将被缓存7200秒(2小时)。

注意:凭据帮助程序将未加密的密码存储在本地磁盘上。

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

git@github.com:org/repo.git  

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