GitHub的使用
Posted yhq1913
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GitHub的使用相关的知识,希望对你有一定的参考价值。
【8】GitHub的使用 通过之前得学习我们可以对本地的仓库做一个很好的管理了,但是对于Git的团队合作使用,还是不够的,本地仓库只是属于我们自己的仓库,为了能够让大家协调工作,我们还需要一个总仓库,每个人的仓库的代码都同步到总仓库中,这样就可以协调工作了,这也是git的分布式版本控制器真正的价值所在,本小节使用GitHub作为总仓库,我们一起来看一下如何创建这个总仓库吧! 首先,登陆GitHub,然后,在右上角找到“Create a new repo”按钮,创建一个新的仓库:

根据提示输入仓库的名称,仓库的描述,以及勾选上 Initialize this repository with a README 这个的意思是说创建出的仓库会自动给我们添加一个README文件,我们需要它做一个项目的简介,最后点击Create Project创建项目,效果如下

好了,以上仓库就创建好了,接下来就是总仓库如何和本地仓库做一个关联

首先点击Clone or download按钮,这个按钮我们可以直接下载项目,下载之后的项目和总仓库没有任何关联,也就是说你无法修改之后进行提交等操作,很显然我们要做的是与总仓库关联,所以选择其他方式,也就是图中所标注的2,我们可以看到一个连接,这是一个SSH连接,我们可以通过这种方式关联,具体操作如下,首先复制标注2处的连接地址

打开本地仓库执行命令: git remote add origin git@github.com:571618587/GitCourse.git (总仓库的地址)执行之后与总仓库建立一个关联,然后通过命令 git pull origin master 命令将服务器端的代码拉取到本地仓库

如果中途出现以下界面,首先按 esc 紧接着shift+:(冒号) 输入q之后回车就可以了

现在我们来看本地的git仓库,就已经把服务器的文件都拉取下来了

下一步就是把我们本地仓库的代码提交到总仓库,使用命令 git push origin master,将本地仓库内容提交到总仓库

现在我们来查看总仓库,会发现本地仓库的文件已经成功的提交到总仓库了

SSH警告 当你第一次使用Git的clone或者push命令连接GitHub时,会得到一个警告:
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)?
这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是 否真的来自GitHub的服务器,输入yes回车即可。 Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了:
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
这个警告只会出现一次,后面的操作就不会有任何警告了。

以上是关于GitHub的使用的主要内容,如果未能解决你的问题,请参考以下文章