Working With Bug Fix and Feature Branches in Git

2011-08-18 / All Blog posts

The project I am currently leading is following A Successful git Branching Model with only a few modifications.

Create a Bug Fix / New Feature Branch

When a developer goes to work on a new task, bug or feature they should make new branch from the develop branch to start their work. The new branch will be named after the Jira task ID.

git checkout develop               // make develop branch current
git pull                           // get latest commits
git checkout -b EDOC-1234 develop  // make new EDOC-1234 branch from develop branch

That creates a new branch for you in your local repository named EDOC-1234 that is based on the develop branch where everyone’s latest work is checked in. From there you can work on your new feature. For example:

echo "42">>theAnswer.txt
add theAnswer.txt
commit -m "Put the answer to life, the universe and everything in theAnswer.txt"
echo "43">>yetMore.txt
add yetMore.txt
commit -m "A present for the god who has everything: one more thing beyond 42"

Update your Bug Fix / Feature Branch with the Latest From the develop Branch

If someone commits to the develop branch while you are working on your feature you can get their work by (re)merging the develop branch to your EDOC-1234 branch:

git checkout develop               // switch to the develop branch
git pull origin develop            // pull the latest changes from the develop branch from origin
git checkout EDOC-1234             // switch back to your feature branch
git merge develop                  // this will add all the changes from the develop branch to your feature branch

Merge your Bug Fix / Feature Branch Back to the develop Branch

When you are done with your feature you need to merge it back the the develop branch.

git checkout develop               // switch the the develop branch
git pull origin develop     // pull the latest commits to the develop branch on origin
git merge --no-ff EDOC-1234        // merge the updates from the develop branch on origin
git push origin develop            // push your merged work to origin

Deleting a Bug Fix / Feature Branch

This will be done after the branch has had a code review and Q/A is complete.

git branch -d EDOC-1234            // remove your feature branch

comments powered by Disqus