2017年8月24日 星期四

[Git 文章收集] DEVELOPING WITH GIT IN A TEAM ENVIRONMENT

Source From Here 
Preface 
I’m posting a doc that my coworker (Neha K.) gave me permission to repost. It’s the set of instructions my company follows to manage our source control and development environment. The basic idea is that we always branch to start development on a new feature or work on a bug. 

Git Development Process 
This is the process we follow for development with Git. Its based on Vincent Dreissen’s “A successful Git branching model”, please read that for a more detailed understanding of the process but keep in mind it has been modified a little to suit our needs. 
 

Main branches 
2 main long running active branches are: 
* develop – branch against which all the development is done.
* master – branch used for all the releases

Naming convention 
* Feature branch: feature-{issueId}
* Hotfix branch: hotfix-{issueId}
* Release tags: v{version-number}

Feature development 
Its recommended to create a feature branch off of develop for any feature development. If the feature is small enough, it can be done directly on develop – that's at the discretion of the developer. But if the feature is for a future release and not the very next one, then a feature branch should be used. Here are steps for developing on a separate feature branch. 

Create the feature branch 
Checkout develop branch 
# git checkout develop

Get the latest from develop 
# git pull

Create the feature branch off of develop and switch to the new branch 
# git checkout -b feature-10 develop

Push the feature branch to central repo 
# git push -u origin feature-10

Commit/push to the feature branch as frequently as you like. 

Merge develop into the feature branch 
If its a branch that spans over multiple days, its advisable to merge develop into the feature branch periodically so that you can make sure work pushed on develop doesnt affect your feature and its also better than doing one big merge into develop on feature completion. 
Checkout develop branch 
# git checkout develop

Get the latest from develop 
# git pull

Checkout feature branch 
# git checkout feature-10

Merge develop branch in 
# git merge --no-ff develop

Push the merged code 
# git push origin feature-10

End the feature branch 
Once the feature development is complete, merge it back to develop and delete it. Getting the latest from the feature branch is relevant if multiple developers worked on the feature branch. 
Checkout feature branch 
# git checkout feature-10

Get the latest from feature-10 
# git pull

Checkout develop branch 
# git checkout develop

Get the latest from develop 
# git pull

Merge feature branch in 
# git merge --no-ff feature-10

Push the merged code 
# git push origin develop

Delete local feature branch 
# git branch -d feature-10

Delete remote feature branch 
# git push origin --delete feature-10

Releases 
Releases are done on master branch. When we are ready to release a new version, make sure that all the features going into that release are merged into develop and then merge develop into master. 

Merge develop into the master branch 
Checkout develop branch 
# git checkout develop

Get the latest from develop 
# git pull

Checkout master branch 
# git checkout master

Get the latest from master 
# git pull

Merge develop in 
# git merge --no-ff develop

Push the merged code 
# git push origin master

Testing is done against master build and all bugfixes are done on master. When the release is ready to go to production, master is tagged and the bugfixes are merged back to develop. Bugfixes can also be continuously merged back into develop on an as-needed basis, rather than waiting for all of them to be done. If its a more involved bugfix, one might want to create a separate branch for it if he/she does not want rest of the release testing to get affected. Instructions below do not show a different bugfix branch. 

Tag the release 
Checkout the master branch 
# git checkout master

Get the latest from master 
# git pull

Tag master with the release version 
// -a: Annotated tag. need a message
# git tag -a v1.0

Push the tag 
# git push origin tag v1.0

Hotfixes 
Hotfixes are done on a separate hotfix branch, created off of master branch. 

Create the hotfix branch 
Checkout master branch 
# git checkout master

Get the latest from master 
# git pull

Create the hotfix branch off of master and switch to the new branch 
# git checkout -b hotfix-12 master

Push the hotfix branch to central repo 
# git push -u origin hotfix-12

End the hotfix branch 
Once the hotfix(es) are done, merge it back to master and develop and delete it. Instead of merging hotfix into develop, master can be merged into develop too after hotfix is merged into master. If latter is being done, replace hotfix branch name with master in the instructions for merging hotfix in develop. Getting the latest from the hotfix branch is relevant if multiple developers worked on the hotfix branch. 
Checkout hotfix branch 
# git checkout hotfix-12

Get the latest from hotfix-12 
# git pull

Checkout master branch 
# git checkout master

Get the latest from master 
# git pull

Merge hotfix branch in 
# git merge --no-ff hotfix-12

Push the merged code 
# git push origin master

Checkout develop branch 
# git checkout develop

Get the latest from develop 
# git pull

Merge hotfix branch in 
# git merge --no-ff hotfix-12

Push the merged code 
# git push origin develop

Delete local hotfix branch 
# git branch -d hotfix-12

Delete remote hotfix branch 
# git push origin --delete hotfix-12

Notes 
* Clean up old branches – To clean up old branches locally, that have been deleted from the remote repo, run this command “git remote prune origin” 
* Merge conflicts – If a merge results in conflicts, you can resolve them manually or run “git mergetool”. This command will help resolve conflicts using a visual diff tool that is configured for git. 

Supplement 
Git 版本控制 branch model 分支模組基本介紹 
Git merge 時使用 fast-forward 的差別 
何時該用 git merge --no-ff? 
3.2 Git Branching - Basic Branching and Merging

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...