您的位置:首页 > 其它

git避免每次push输入密码

2015-11-22 22:50 309 查看
(全部命令在bash终端中输入)1. 在$HOME$目录下(不知道的话,可以执行echo $HOME$查看,一般是C:\user\administrator),执行touch .git-credentialsvim .git-credentials https://{username}:{password}@github.com (创建git-credentials文件,编辑内容为.https://{username}:{password}@github.com)2.将配置文件添加到全局配置中,执行:gitconfig --global credential.helper store执行完后,在$HOME$目录的.gitconfig文件中,多了一个配置:
[credential]
helper = store
一般配置完上面两步就可以了,但是由于我clone git代码库的时候,使用https地址,所以还需要如下步骤修改为ssh验证才可以,继续:
3.进入代码库目录中,查看.git/config文件
原始为:
[remote "origin"]fetch = + refs/heads/*:refs/remotes/origin/*url = https://username@github.com/username/td.git[/code;'>[code=plain" style="line-height: 20.7999992370605px; white-space: pre-wrap; color: rgb(51, 51, 51); background-color: rgb(245, 245, 245);]
修改为:
[remote "origin"]fetch = + refs/heads/*:refs/remotes/origin/*url = git@github.com:username/TD.git
4.生成公钥、密钥对:
执行“ssh-keygen -t rsa -C "{你的邮箱名}@163.com",生成id_rsa(密钥)和id_rsa.pub(公钥)
5. 将公钥(rsa.pub)中的内容拷贝,在www.github.com自己的账户中执行ADD SSH Key操作,name随便起(最好写自己代码库的名称),vlaue就是刚才拷贝的公钥内容
至此,重新打开git bash,执行git push命令后,就不需要再输入用户名、密码了

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: