1.Git简介
Git是一个分布式版本控制工具,适用于管理
大型开源软件源码
个人软件源码
私人文档
…
在不同粒度上进行版本控制,能够得到任意一个版本的内容
仓库(repository)
分支(branch)
每一次的改动(commit)
2.Git项目分布框架
项目存储于远程版本库中
Collaborators拥有直接修改远程仓库内容的权限
其他人通过提交PR的方式修改内容
3.Git项目版本框架
一个项目为一个Repository
一个Repository可包含多个分支(Branch)
通常不同版本对应不同分支
一个分支由若干Commit构成
一个Commit表示一次内容修改
一个Commit可以包含对多个文件内容的修改
一个PR可以包含多个Commit
4.安装Git
这里的安装主要是指Git的客户端
For Windows
Git for Windows (适合shell 命令使用)
GitHub Desktop(良好界面的桌面应用,仅适合Github)
For Linux
apt-get install git
yum install git
安装完后git --version 检查版本
5.使用Git
同步最新的项目至本地
作为Collaborator
git pull
非Collaborator
git fetch upstream
git merge upstream/somebranch
至此,本地代码已更新
git push origin somebranch:somebranch
至此,远程仓库代码已更新
分支管理
查看本地分支git branch
查看远程分支git branch -r
创建本地分支git branch [name]
切换分支git checkout [name]
删除分支git branch -d [name]
创建远程分支git push origin [name]
删除远程分支git push origin :[name]
使用Git
对开源项目作贡献的一般流程
fork a repository
git clone https://github.com/PasaLab/tachyon.git
git checkout master
git remote add upstream https://github.com/Alluxio/alluxio.git
git fetch upstream
git merge upstream/master
git checkout –b new-branch
(本地修改内容)
git add
git commit –m “modify something”
git push origin new-branch:new-branch
create a pull request
其他
Git参考手册http://gitref.org/zh/index.html
GitHub https://github.com/
https://help.github.com/articles/create-a-repo/
https://help.github.com/articles/fork-a-repo/
https://help.github.com/articles/using-pull-requests