Skip to content

Working with Branches

Vlad Dumitrescu edited this page Oct 27, 2010 · 1 revision

So you’ve read “Working with Git” and have your fork of the erlide repository. You’re way ahead of things because you’ve also read “Contributing a Bug Fix” and perhaps contributed a bug fix or two. Well, now you’ve reached the point where you need to fix a bug in a maintenance branch. This document is for you.

In erlide, a “maintenance branch” is a Git branch that is used to maintain a major release of erlide, as well as older releases. As of this writing, the maintenance branch is rev_0_6, where we maintain the code for erlide 0.6.×. There are also branches for older unmaintained branches. You may ignore those.

It’s important to fix bugs in the current maintenance branch because a lot of people are using it, and we routinely issue maintenance releases. So let’s say that you decide that you’d like to fix some bugs in the rev_0_6 branch. Here’s how you do that with Git.

First, change directories into your checkout of your fork of the erlide repository, and create a local branch to track the branch maintained upstream:

cd erlide
git fetch origin
git checkout --track -b rev_0_6 origin/rev_0_6

The call to git fetch origin makes sure that you have copies of all the remote branchs. Then the call to git checkout creates a new local branch, named “rev_0_6”, and sets it to track the branch of the same name stored in your fork of erlide. This means that when you make changes to your local rev_0_6 branch and push them back to GitHub, they’ll be pushed to the remote rev_0_6 branch.

You only need to create the local tracking branch once in your local repository. Once that’s done, you can always switch to it in the future using git checkout:

git checkout rev_0_6
git pull origin

Now you’re ready to go ahead and fix the bugs, push them to your fork (git push will push to the tracked fork), send pull requests, and all the rest, as described in “Contributing a Bug Fix”. When you’re done, you can always switch back to the master branch simply by checking it out:

git checkout master

Yep, that’s really all there is to working with existing branches. Have fun!

This page is adapted from the pages written by David E. Wheeler for bricolage and is covered by a Creative Commons license. Thanks a lot!

Practical advice

Some things that I do to make the administration a little easier:

  • In my own github fork I removed the next,pu and later branches. There is only master and my workbranches. This is because “my” next and pu were just following the ones from upstream, so it’s just as well to use the upstream branches (which happens only when merging).
  • When a branch is delivered to master or next, I also remove it from my github fork (with git push vlad :branch-name). Old branches cause confusion (is this to be kept or old junk? do I need to rebase it?)
  • I always do merges from workbranches to master/next/pu, never in the other direction. If that becomes necessary because of some serious problem, I would rebase the workbranches instead. Minimizing cross-merges leads to much less headache when merging.

Clone this wiki locally