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 workflow 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.