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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

一、背景

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、免密拉取配置

1cd到~/目录下创建一个文件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’

注意

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

三、总结

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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: linux