(全部命令在bash终端中输入)
1. 在$HOME$目录下(不知道的话,可以执行echo $HOME$查看,一般是C:\user\administrator),执行
touch .git-credentials
vim .git-credentials
https://{username}:{password}@github.com
(创建git-credentials文件,编辑内容为.https://{username}:{password}@github.com)
2.将配置文件添加到全局配置中,执行:
git config --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
修改为:
[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命令后,就不需要再输入用户名、密码了