git创建公钥,远程代码仓库

git创建公钥

$ ssh-keygen -t rsa -C "youremail@example.com"
你需要把邮件地址换成你自己的邮件地址,然后一路回车,使用默认值即可,由于这个Key也不是用于军事目的,所以也无需设置密码。

如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。

第2步:登陆GitHub,打开“Account settings”,“SSH Keys”页面:

然后,点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容:

要关联一个远程库,使用命令

git remote add origin git@server-name:path/repo-name.git

 

关联后,使用命令

git push -u origin master

 

第一次推送master分支的所有内容;

此后,每次本地提交后,只要有必要,就可以使用命令

git push origin master

 

推送最新修改;



要克隆一个仓库,首先必须知道仓库的地址,然后使用git clone命令克隆。

git clone git@server-name:path/repo-name.git

 

Git支持多种协议,包括https,但通过ssh支持的原生git协议速度最快。

posted on 2014-10-12 23:11  walter371  阅读(256)  评论(0)    收藏  举报

导航