GitHub之创建共享版本库

在GitHub官网创建账号,将本地库信息上传到共享库中去。


1、访问官网github.com,注册账号



注册账号后需要通过邮箱激活此账号


2、新建版本库





3、新建一个本地库

$ mkdir myGitHome

$ cd myGitHome

$ git init

$ vim test.c     //随便写个东西

$ git add test.c

$ git commit test.c -m "add test.c"


4、绑定账号(使用GitHub上的用户名、邮箱)

$ git config --global user.name "stone927"

$ git config --global user.email "[email protected]"


5、创建ssh-key

本地库与网络库使用SSH通信,因此需要创建key

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

使用GitHub上注册的邮箱,密码可不填

成功创建后可在~/.ssh/目录下看到id_rsa、id_rsa.pub私钥、公钥两个文件

完全复制id_rsa.pub中的内容,拷贝到GitHub中




使用如下命令测试结果,需要输入github登陆密码

$ ssh -T [email protected]

出现如下信息表示成功

Hi stone927! You've successfully authenticated, but GitHub does not provide shell access.
(有时不成功可尝试重启计算机)

6、获取版本库地址



7、关联本地库与网络库

$ cd myGitHome

$ git remote add test https://github.com/stone927/test.git
(test为库名称,可任意设置)


8、获取网络库内容

$ git pull --rebase test master
(test为库名称,master表示主分支)


9、提交本地内容到网络库

$ git push -u test master


10、克隆版本

从网络库拷贝一份完整的库

$ mkdir myGitHome1

$ git clone https://github.com/stone927/test.git