The Git 'topic branch' workflow (pattern)

In this short article, I'll demonstrate the typical workflow for using a Git topic branch. If you've never heard of a topic branch, here's a description from the excellent book, Pro Git:

"A topic branch is a short-lived branch that you create and use for a single particular feature or related work.

This is something you’ve likely never done with a VCS before because it’s generally too expensive to create and merge branches. But in Git it’s common to create, work on, merge, and delete branches several times a day."

The basic Git topic branch pattern looks like this:

create a new branch (our 'topic branch')
$ git branch bug1945

switch to the new branch
$ git checkout bug1945

do your work on the branch ...

commit your changes
$ git commit -a -m 'fixed bug 1945'

merge the changes back to the master
$ git checkout master
$ get merge bug1945

delete your topic branch
$ git branch -d bug1945

create another topic branch ...

That's all there is to the basic Git topic branch workflow/pattern. Here's a quick review:

  1. Create a new topic branch to work on your next feature.
  2. Make your changes to the code.
  3. Merge the changes back to the master.
  4. Delete your branch.

Related Git branch commands

Here's a short list of Git commands related to the concept of topic branches:

create a branch and check it out in one step
$ git checkout -b bug1945

list your current branches
$ git branch

a little more information about the current branches
$ git branch -v

use the gui merge tool to see your merges
$ git mergetool

Git topic branch workflow: Summary

In summary, I hope this short tutorial on the concept of the Git topic branch workflow has been helpful.

Reporting live from Boulder, Colorado, this is Alvin Alexander. To keep up with my new tutorials, here's a link to the RSS feed, and here's a link to me on Twitter.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.