Github对我们IT从业人员的重要性不言而喻,这里将自己学习Github的笔记整理出来,方便日后查询,也作为技术博客与大家一起分享。
第一步:安装Git工具。这里就不细说,与普通软件的安装没有什么区别,也很少有人会在这里出错。点击下载git工具
第二步:在本地创建一个文件夹,取一个合适的名字。并跳转到这个文件夹中。

- 第三步:在本地创建Git可进行管理的仓库。

这个时候在我们创建的这个文件夹里面会多出一个隐藏的文件夹.git,这是git工具用来跟踪和管理仓库的文件夹。我们看到了这个文件夹,就说明我们成功在本地创建了一个仓库。

- 第四步:将我们的项目文件/文件夹拷贝到我们之前创建的文件夹中,并使用
git add .
命令将我们的项目代码添加到我们的仓库中。


我们可以使用git status
命令来查看我们项目代码的状态。在上传代码的整个过程中,我们都可以使用这个命令来跟踪查看项目代码的状态。

- 第五步:使用
git commit -m "上传代码的注释描述"
命令将我们的项目代码提交到我们的本地仓库中。注意这一步中,-m "上传代码的注释描述"
要加上,否则可能会报错。

- 第六步:创建SSH KEY,通过以下命令会生成两个文件id_rsa和id_rsa.pub。如果之前你看过其他的教程,曾经生成过这两个文件,那么可以跳过第六步。
$ ssh-keygen -t rsa -C "youremail@example.com"
生成的两个文件会保存的C盘的用户目录下,我们可以使用系统自带的搜索功能搜索出来,或者你参考下图,将这连个文件找出来

- 第七步:设置SSH加密传输以及新建我们的远程仓库。使用我们的账号登录Github官网,点击settings,然后点击SSH and GPG KEYS。

这里的Tilte栏目是填写一些描述性的词语,然后将id_rsa.pub文件中的内容全部复制到Key栏目中。然后点击Add SSH key。这一步我们就完成了SSH Key加密,是用在本地仓库和Github仓库进行加密传输中间。

新建我们的Github仓库。点击加号,选择New repository,然后填写一个合适的名字即可,然后点击Create repository。这里注意一下,最后有一个是否生成一个README选项,我们不要勾选,否则后面在使用命令的时候可能会踩到坑。

在Github上创建好我们的仓库之后,我们留意一下我们的仓库地址,后面在本地连接远程仓库的时候会用到。

在Github上创建的仓库有两个地址,HTTPS地址和SSH地址。一般情况下我们使用SSH地址即可。
- 第八步:将本地仓库和Github中的仓库(即远程仓库)进行关联

- 第九步:通过命令将我们本地仓库中的代码上传到远程仓库中
git push -u origin master

这个时候我们刷新我们的Github仓库,就可以发现代码已经上传成功;

使用Git工具管理Github时候的常见错误:
常见错误:remote origin already exists.
解决方法:
- 先删除远程的Gitithub的时候
$ git remote rm origin
- 在添加远程Git仓库
$ git remote add origin 远程仓库地址