Git 是 Linus Torvalds 在 2002 年用 C 语言编写的一个**分布式版本控制系统**。 --- [TOC] 如未说明,尖括号 <> 内的内容表示其并非 git 命令参数,而是用户定义的内容(如具体 仓库名、分支名、文件名等等)。 参考:[git-scm](https://git-scm.com/book/zh/v2) [git 简明指南](https://rogerdudler.github.io/git-guide/index.zh.html) [图解 git](https://marklodato.github.io/visual-git-guide/index-zh-cn.html) [git 参考手册](http://gitref.org/zh/creating/) [archlinux-wiki:git](https://wiki.archlinux.org/index.php/Git_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)) [猴子都能看懂的 git 入门](http://backlogtool.com/git-guide/cn/) --- # 安装和初始设定 * 安装 git Linux:根据发行版不同,使用安装命令安装`git`包。 Mac OS X :安装 Xcode,自带 git,或 `brew install git`。 Windows :[Git for Windows](https://git-for-windows.github.io/) * 图形化 git 例如: * gitk 命令行自带图形界面,在 git 仓库中执行`gitk`或在任何地方执行`git gui`启动。 * [gitkraken](https://www.gitkraken.com/) * [source tree](https://www.sourcetreeapp.com/) * [github desktop](https://desktop.github.com/) * [git-cola](https://git-cola.github.io/) - 初始设定 设置用户名和邮箱,图形界面到其相关设置选项里设置,命令行: ```shell git config --global user.name "Your Name" git config --global user.email "email@example.com" ``` 更多设置见后文 --git[配置](#配置) 从本地仓库向远程仓库推送的基本操作流程: 在本地仓库内进行操作 - > 在[本地仓库创建快照版本](#提交快照)-> 将本地仓库快 照[推送到远程仓库](#推送和下载分支) # 仓库创建和远程关联 ## 创建本地仓库 * 创建(/ 初始化)仓库 :`git init` * 仓库空间划分概念: * **工作区**(working directory ):存放当前工作文件 * **暂存区**(stage):存放通过`git add`添加的文件。 * **版本库**(repository ):项目的各个版本(快照)。 ## 关联远程仓库 将本仓库与其他仓库关联(例如远程服务器上的仓库),以推送本地仓库数据到关联的仓库中。 - 添加关联 可以克隆远程仓库或者直接添加远程仓库信息以进行关联: - 克隆仓库:`git clone ` 几种不同的协议示例: ```shell git clone https://example.com/path/to/repo-nam.git git clone git@example.com:someone/path/to/repo-name.git git clone ssh://example.com/path/to/repo-name.git git clone git://example.com/path/to/repo-name.git ``` 此外还支持 ftp、git 、 rsync 等协议。 - 克隆远程仓库的某个分支 ```shell git clone -b ``` 分支相关信息参看[分支管理](#分支管理) - 直接添加远程仓库信息 ```shell git remote add [