Git的杀手级功能之一:远程仓库
远程仓库概念
在前面的学习中,我们学习到了Git是分布式版本控制系统,这意味着,同一个Git仓库,可以发布到不同的机器上.要体现分布式,从概念上来看,至少需要两台电脑,当然同一台电脑也可以克隆很多版本库,但没有什么实际含义.
这样来看,我们要学习Git的分布式,需要另外一台电脑,最好24小时运行,充当服务器.Git服务器,完全可以自己搭建,不过不是我们现在学习的重点,暂时先加入代办事项.我们可以用GitHub来免费获取Git远程仓库.
GitHub配置
$ ssh-keygen -t rsa -C "youremail@example.com"
把邮箱换成自己的邮箱
然后一路回车
最后在 用户名/.ssh 目录下,看到这几个文件

-
文件含义
-
id_rsa 是私钥,自己保管,不能泄露出去 -
id_rsa.pub 是公钥,可以放心的告诉别人 -
GitHub配置




这样,GitHub的配置就完成了
添加远程库
我们有两种场景
先看第一种
- 在GitHub创建新仓库


其它默认即可
- 获取链接:

- 同步:
$ git remote add origin git@github.com:taroandpuff/webLearn.git
注意把taroandpuff换成自己的账户名
$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 336 bytes | 336.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:taroandpuff/webLearn.git
3bcb16f..0db054d master -> master
branch 'master' set up to track 'origin/master'.
- 就完成同步:

- 注意事项:
如果警告:
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?
是因为在SSH第一次验证GitHub服务器的Key时,需要你确定GitHub的Key的指纹信息是否真的来自GitHub的服务器,yes回车即可
还会有警告:
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
这个警告只会出现一次,回车即可
第二种:
- 新建一个
gitskills 仓库

同时加一个README文件
- 获取链接:

- 同步:
$ git clone git@github.com:taroandpuff/gitskills.git
Cloning into 'gitskills'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3
Receiving objects: 100% (3/3), done.
- 这样就完成了同步
$ git remote -v
origin git@github.com:taroandpuff/webLearn.git (fetch)
origin git@github.com:taroandpuff/webLearn.git (push)
查看远程库信息
$ git remote rm origin
注意这样只是解除了本地和远程仓库的联系,没有在物理上删除远程仓库
如果需要在物理上远程删除远程仓库,需要在GitHub平台上操作
|