1.创建SSH Key。
在用户主目录(C:\Users\Administrator)下,看看有没有.ssh文件,如果有,再看文件下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接到下一步。如果没有,打开Git Bash,输入命令,创建SSH Key
$ ssh-keygen -t rsa -C "123@126.com"
//123 是你自己注册GitHub的邮箱
去用户主目录里找到.ssh文件夹,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露,id_rsa.pub是公钥,可以公开。
2.添加ssh keys
- 接下来到GitHub上,打开“Account settings”–“SSH Keys”页面,然后点击“Add SSH Key”,填上Title(随意写),在Key文本框里粘贴 id_rsa.pub文件里的全部内容。
3.验证是否成功
- 在git bash里输入下面的命令
ssh -T git@github.com
4.添加远程仓库
git remote add origin git@github.com:miracleo/MyRepository.git
5.如果仓库是空的
git push -u origin master
6.如果仓库不是空的
- 先将仓库压缩在一起
git pull --rabase origin master
- 再进行推送
git push origin master