Git and libgit2

Bug Fix and Feature Branches in Git

Published 2011-08-18.
Time to read: 1 minutes.

This page is part of the git collection.

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, which in the following example is EDOC-1234.

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

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

Shell
$ echo "42">>theAnswer.txt
$ add theAnswer.txt
$ commit -m "The answer to life, the universe and everything"
$ 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:

Shell
$ git checkout develop     // switch to the develop branch
$ git pull origin develop  // pull the latest changes from the develop branch at origin
$ git checkout EDOC-1234   // switch back to your feature branch
$ git merge develop        // 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, merge it back to the develop branch.

Shell
$ 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.

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


* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.