linux下解决 git clone每次都要输入用户名密码问题(推荐)

一、背景:

git clone代码或者push代码时候需要输入账号密码

二、解决方法:

1、ssh方式:

先用git config –global user.name ‘username’和git config –global user.email ‘xxx@xxx.com’配置一下用户名和邮箱
生成ssh公钥:ssh-keygen -t rsa -C “xxxxx@xxxxx.com”,查看~/.ssh/id_rsa.pub文件内容,获取到你的public key,粘贴到GitLabssh公钥管理处即可
使用git clone http://git.gitxxx.com/xxx.git,先测试一下,看能不能拉取成功。如果成功,向下进行。此时还是会询问用户名和密码的。

2、免密拉取配置

(1)cd到~/目录下,创建一个文件:touch .git-credentials
vim .git-credentials
(2)然后输入https://{username}:{password}@git.gitxx.com,比如http://fengjiaheng:password@git.gitxx.com
(3)然后执行:git config –global credential.helper store
(4)然后使用git config –list或者查看一下~/.gitconfig文件,会发现多了一行[credential] helper = store
(5)这时候再用 git 拉取仓库就不需要输入用户名和密码了。
注意:第4步必须要做,否则做完4、5步之后也不能免密码拉取成功,需要再次执行第4步骤。

3、粗暴使用型

Git Clone命令直接使用用户名密码Clone

git clone http://userName:password@链接
修改为 git clone https://username:password@链接

示例:
git clone git@http://112.12.122.22:t-mapi/hotel-tapi.git
修改为
git clone ‘http://username:password@112.12.122.22:t-mapi/hotel-tapi.git’

注意:

(1)http -> https
(2)如果账号username或者password中有@符号,需要 将@替换为%40
(3)如果报错git clone event not found,需要将 git clone 后地址加上引号 ‘’

三、总结:

1、第二种方法比较简单(推荐使用),但是第一二种方法中都首次都必须自己输入账号密码
2、第三种一次都不用输入账号密码(推荐使用)

到此这篇关于linux下解决 git clone每次都要输入用户名密码问题的文章就介绍到这了,更多相关git clone输入用户名密码内容请搜索aitechtogether.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持aitechtogether.com!

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2023年4月26日
下一篇 2023年4月26日

相关推荐

此站出售,如需请站内私信或者邮箱!