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

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


当前回答

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

ssh-add

ssh-add - k

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

其他回答

将git客户端连接到操作系统凭据存储。例如,在Windows中,您将凭据帮助器绑定到wincred:

git config --global credential.helper wincred

在GitHub上使用https://时是否有办法跳过密码输入?

只是想指出上面说过几次的解决方案:

git config credential.helper store

在此之后,您可以使用任何需要密码的命令。你不需要用力。之后,你就不需要再输入你的用户名/密码了。

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

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

这一切都是因为git在克隆/拉/推/取命令中没有提供通过管道发送凭证的选项。尽管它提供了证明。Helper,它存储在文件系统或创建一个守护进程等。通常,GIT的凭据是系统级的凭据,调用GIT命令的应用程序有责任保证它们的安全。非常不安全。

以下是我必须解决的问题。 1. Git版本(Git——version)应该大于或等于1.8.3。

吉特克隆

对于克隆,使用“git克隆URL”,将URL的格式从http://{myuser}@{my_repo_ip_address}/{myrepo_name.git}改为http://{myuser}:{mypwd}@{my_repo_ip_address}/{myrepo_name.git}

然后清除存储库中的密码,如下一节所示。

清除

现在,这个已经消失了

written the password in git remote origin. Type "git remote -v" to see the damage. Correct this by setting the remote origin URL without password. "git remote set_url origin http://{myuser}@{my_repo_ip_address}/{myrepo_name.git}" written the password in .git/logs in the repository. Replace all instances of pwd using a unix command like find .git/logs -exec sed -i 's/{my_url_with_pwd}//g' {} \; Here, {my_url_with_pwd} is the URL with password. Since the URL has forward slashes, it needs to be escaped by two backward slashes. For ex, for the URL http://kris:passs123@192.168.0.1/proj.git -> http:\\/\\/kris:passs123@192.168.0.1\\/proj.git

如果您的应用程序使用Java来发出这些命令,请使用ProcessBuilder而不是Runtime。如果必须使用Runtime,请使用getRunTime()。exec以字符串数组作为参数,以/bin/bash和-c作为参数,而不是以单个字符串作为参数。

GIT FETCH/PULL / PUSH

在git远程url中设置密码为:"git remote set_url origin http://{myuser}:{mypwd}@{my_repo_ip_address}/{myrepo_name.git}" 发出git fetch/push/pull命令。然后将不会提示您输入密码。 按照前一节的方法进行清理。不要错过。

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

ssh-add

ssh-add - k

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