你将收获
- 了解使用 Git 的机制
- 介绍 Git 功能分支工作流程
- 了解 Git 如何鼓励协作
- 成为一名社交程序员
如何成为 Git 绝地武士
规则#1:为每个新项目创建一个 Git 存储库
规则#2:为每个新功能创建一个新分支
规则#3:使用 Pull 请求将代码合并到 Master
Git
Github
Git 是工具,Github 是网站
Git 命令工作流程
Git 功能分支工作流程
详细的功能分支工作流程
- CLONE a Repository (FORK first if not part of Dev Team)
- Assign the ISSUE for your work to yourself and place it in working status
- Create a BRANCH to work on an ISSUE
- Run the Test suite to make sure you can run the code
- Make changes to code and test cases and COMMIT to local BRANCH
- Run the Test suite early and often to make sure you didn’t break anything
- PUSH changes to remote BRANCH
- Did we mention testing the code early and often?
- Create PULL REQUEST when all tests pass and code is ready for review / MERGE
示例
git checkout master
git pull
git checkout -b my-new-feature
git add .
git commit -m 'initial working version of my new feature'
git push -u origin my-new-feature
... write some code here ...
git add .
git commit -m 'added this cool code...'
git push
git checkout master
git pull
git checkout my-new-feature
git merge master
... fix any merge conflicts here ...
git add .
git commit -m 'merged updates from master'
git push
git checkout master
git pull
git branch -d my-old-feature
git checkout -b my-new-feature
- 删除旧分支
- 为新功能创建一个新分支