思维导图

一、安装git
1. OS系统上直接安装x-code即可,其自带git
2. 其余系统请参考廖雪峰官方网站
二、本地创建版本库
1. 本地新建版本库
1)新建版本库文件夹(名字随意)
2)初始化版本库
- 初始化
$ git init - 查看是否生成.git文件(即版本管理文件);它是隐藏文件,用以下命令可查看
$ ls -ah
2. 版本库的使用
1)工作区与暂存区
- 工作区即你在本地的版本库文件夹
- 暂存区(stage)即存在于.git文件之中,用来中转需要提交的文件
- 运行机制:工作区(add)→暂存区(commit)→git(push)→github(到这成功)

2)管理修改工作
-
工作区修改提交至暂存区
$ git add 'filename' //注意有多个文件需要提交的话重复该命令即可 $ git add 'filename2' //类似于这种就是第二份文件 $ git add . //提交所有变动,简单粗暴 <!--注意:空文件夹无法提交,提交文件夹实质实在提交文件-->
-
暂存区文件提交至git
$ git commit -m '这是注释' //-m 是每次修改的备注
三、利用github远程托管版本库
1. 注册github账号并登陆
2. 获取本机的SSH公钥
1)输入获取代码,回车直到出现图片所示图形为止
$ ssh-keygen

2)输入编译代码
$ vim ~/.ssh/id_rsa.pub
3)出现SSH公钥后,将红框部分复制,并在下方输入:q,随后按下回车可以退出该窗口

4)进入到github页面设置SSH公钥
- 点击用户下拉菜单中的settings(step1)
- 点击左侧的SHH and GPG keys(step2)
- 在Title中输入公钥名称(随意)(step3)
- 在key中贴上SSH公钥(step4)

3. 创建新的仓库
1)创建新的仓库(repository)
- 点击用户左侧的+号菜单中的New repository(step1)
- 在repository name中输入仓库名称,随意取名
- 是否公开选项可以选取Public(step3)
- 勾选step4处,会自动生成一份可编辑的README.md文件(建议勾选)(step4)
- 点击create repository生成仓库完毕(step5)

2)查看新建的仓库(repository)
- 可以回到github个人首页点击右侧的仓库区

3)关联本地版本库与远程仓库(仅首次需要关联)
$ git remote add origin 后面跟上你的远程仓库的SSH地址

4)本地版本库推动至远程
$ git push -u origin master

网友评论