Search code examples
gitbranchmsysgit

Is there an easy way to change to previously active branch?


I'm using git (in fact, msysgit) 1.6.4 on Windows. Most of the time I'm doing work in some feature branches. Every now and then, I want to hop back to master to cherry-pick one particular commit I did in my feature branch - usually because it's a useful bugfix which makes sense even without the feature. My workflow is like this - if this is unnecessarily complicated, please tell me :-) :

git checkout -b mycoolfeaturebranch
// hack away, implementing a feature and one bugfix (while I'm at it)

git add file_with_bugfix.cpp
git commit -m "Fixed bug 12345  // commit the bugfix
git checkout master             // hop over to master
git cherry-pick                 // bring the bugfix into master

At this point, I usually want to hop back to my feature branch to continue work on the feature. Unfortunately, my branch names tend to become a little long (like, 'mycoolfeaturebranch') and I don't have git branch name tab completion on Windows.

Is there maybe something like cd - on Unix shells (which hops to the previous directory, useful for toggling between two directories)? A git checkout - would be great. :-)


Solution

  • From $GIT/Documentation/RelNotes-1.6.2.txt:

    • "git checkout -" is a shorthand for "git checkout @{-1}".

    Did you try it?