Friday 14 March 2014

Git branch management


Branch management is very important especially when git project is shared by team. Project can set branches, when a programmer works on the branch, it won’t interrupt others work. When the sub-tasks finished, the programmer can merge the branch so that it can be visible to others.

Usually the project should have a default branch called master as below



    















create an branch



command:

git branch test          # create an branch called test
git checkout test        # switch to the branch called test

or:
git checkout –b test    # create a test branch and switch to it.

now git repository is like:















 modify the test branch and commit it




merge the master and test branch



git checkout master       #you need switch to the branch you want to merge
git merge test            #merge the branch now

now it is like:


















delete the branch if not used any more


commands:      git branch –d test



















a short summary of basic branch management commands:
  • check the branch status            #git branch
  • create an branch                   #git branch bname
  • switch to a branch:               #git checkout bname
  • create and switch to the branch:  #git checkout -b bname
  • merge the branch to current branch:#git merge bname
  • delete the branch:                 #git branch -d bname

branch conflicts management

when the two branches are both made changes, they can’t be merged directly.


You will have to manually fix the conflicts then merge the file

there are some practical rules for branch management

  1. project has a stable and release branch called master
  2. project should have other sub-main branches as test, dev, uat
  3. team members should create their own branches from test, dev. They should not create branch from master directly
  4. team members should merge their codes to dev or test
  5. master can only be merged from one single branch, eg dev.

No comments:

Post a Comment