GIT免密pull和push

git每次pull和push时都需要输入用户名密码太繁琐,可以通过设置避免这个不必要的操作。

有两种方法:

1、http方式,指定用户名和密码,git clone时指定:

git clone http://user:[email protected]/project.git

如果早就clone了项目,则重新设置一下remote url,具体命令:

git remote -v #可以查看目前的url
git remote set-url origin http://user:[email protected]/project.git

2、ssh方式,先要在本机生成公私秘钥,具体命令:

ssh-keygen -t rsa

一路回车,命令执行完成,会在~/.ssh目录下生成id_rsa(私钥)和id_rsa.pub(公钥)。打开id_rsa.pub文件,复制公钥内容,然后打开github,在User Settings/SSH Keys中添加刚才复制的公钥内容,保存即可。

以上两种方法设置好后,git pull和git push都不需要再输入用户名密码了。

猜你喜欢

转载自blog.csdn.net/bodybo/article/details/80547057
今日推荐