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

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


当前回答

使用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  

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

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

我建议使用凭证管理器来存储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在克隆/拉/推/取命令中没有提供通过管道发送凭证的选项。尽管它提供了证明。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命令。然后将不会提示您输入密码。 按照前一节的方法进行清理。不要错过。

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

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