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

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


当前回答

看起来,至少在Windows上使用TortoiseGIT时,可以创建SSH密钥并将其传输到GIT服务器,只需使用:

> ssh-keygen.exe
> ssh-copy-id [username]@[GIT_server]

其他回答

我建议使用凭证管理器来存储GitHub凭证。使用git config——global credential。助手存储是不安全的,因为它以明文存储GitHub密码。 对于Linux, libsecret是一个很好的替代方案。对于Ubuntu和其他一些linux发行版,您可以执行以下操作:

安装:

sudo apt-get update
sudo apt install libsecret-1-0 libsecret-1-dev
sudo apt install gnome-keyring

创建

cd /usr/share/doc/git/contrib/credential/libsecret/
Sudo make 

配置git使用libsecret存储密码

git config --global credentail.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

在此设置后输入一次密码后,git凭据将由libsecret存储。

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

你必须设置一个SSH私钥,你可以看看这个页面,如何在Mac上进行设置,如果你在linux上,指南应该是差不多的,在Windows上你需要像MSYS这样的工具。

这一切都是因为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命令。然后将不会提示您输入密码。 按照前一节的方法进行清理。不要错过。

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

git config --global credential.helper wincred

请参考以下github文档:

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