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

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


当前回答

第一步-

使用以下命令在linux系统上创建SSH密钥

ssh-keygen -t rsa -b 4096 -C "your_email"

它将询问密码短语和文件名(默认为~/)。ssh / id_rsa ~ / . ssh / id_rsa . pub)

步骤2 -

一旦文件创建,添加公钥id_rsa。Pub到github帐户SSH部分。

第三步-

在您的机器上,使用以下命令将私钥id_rsa添加到ssh-agent

ssh-add ~/.ssh/id_rsa 

步骤4 -

现在使用以下命令将远程url git@github.com:user_name/repo_name.git添加到本地git repo中。

git remote remove origin
git remote add origin git@github.com:user_name/repo_name.git

这是它。

其他回答

第一步-

使用以下命令在linux系统上创建SSH密钥

ssh-keygen -t rsa -b 4096 -C "your_email"

它将询问密码短语和文件名(默认为~/)。ssh / id_rsa ~ / . ssh / id_rsa . pub)

步骤2 -

一旦文件创建,添加公钥id_rsa。Pub到github帐户SSH部分。

第三步-

在您的机器上,使用以下命令将私钥id_rsa添加到ssh-agent

ssh-add ~/.ssh/id_rsa 

步骤4 -

现在使用以下命令将远程url git@github.com:user_name/repo_name.git添加到本地git repo中。

git remote remove origin
git remote add origin git@github.com:user_name/repo_name.git

这是它。

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

ssh-add

ssh-add - k

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

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

git@github.com:org/repo.git  

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

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

$ git push --repo https://name:password@bitbucket.org/name/repo.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小时)。

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