Git与Github的连接

参考资料:https://www.cnblogs.com/flora5/p/7152556.html

1. 创建一个仓库,记录下仓库名,例如为:examples

2. 创建SSH Key。

在用户主目录(C:\Users\Administrator)下,看看有没有.ssh文件,如果有,再看文件下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接到下一步。如果没有,打开Git Bash,输入命令,创建SSH Key

 ssh-keygen -t rsa -C "[email protected]" 

其中[email protected]"是你自己注册GitHub的邮箱,直接回车即可。再去用户主目录里找到.ssh文件夹,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露,id_rsa.pub是公钥,可以公开。

3.在GitHub中添加Add SSH Key

到GitHub上,打开“Account settings”–“SSH Keys”页面,然后点击“Add SSH Key”,填上Title(随意写),在Key文本框里粘贴 id_rsa.pub文件里的全部内容。

4.验证是否成功,在git bash里输入下面的命令

ssh -T [email protected]

如果初次设置的话,按要求输入yes 同意即可。

5.开始设置username和email

因为github每次commit都会记录他们。

git config --global user.name  "name"//你的GitHub登陆名
git config --global user.email "[email protected]"//你的GitHub注册邮箱

6.本地仓库上传到github

git remote add origin [email protected]:flora0103/example.git    
git push -u origin master  

1表示关联一个远程库命令,[email protected]:flora0103/example.git 这个是自己远程库
2表示关联后,第一次推送master分支的所有内容命令,此后,每次本地提交后,就可以使用命令git push origin master推送最新修改。

猜你喜欢

转载自blog.csdn.net/sinat_30967935/article/details/82961879
今日推荐