Checkout the Previous Branch with git

By  on  

Command line shortcuts are can be a huge time saver, which is why I like creating bash aliases and and enjoy other tricks I've found.  I do have a list of tasks I don't yet have a shortcut for, like easy switching between my current branch and the previous branch.  I have to do this often when I update master via remote pull and then rebasing a feature branch, and since many of my branch names include a hard to remember bug number, switching between branches is a pain.

I recently found out that you can switch the the previous branch you were on using the following command:

git checkout master

# Do whatever
git pull remote master

# Go back to the previous branch
git checkout -

Using - references the previous branch name, thus allowing you to navigate branches with ease!

Recent Features

Incredible Demos

  • By
    Create Twitter-Style Buttons with the Dojo Toolkit

    I love that JavaScript toolkits make enhancing web pages incredibly easy. Today I'll cover an effect that I've already coded with MooTools: creating a Twitter-style animated "Sign In" button. Check out this five minute tutorial so you can take your static...

  • By
    Fancy Navigation with MooTools JavaScript

    Navigation menus are traditionally boring, right? Most of the time the navigation menu consists of some imagery with a corresponding mouseover image. Where's the originality? I've created a fancy navigation menu that highlights navigation items and creates a chain effect. The XHTML Just some simple...

Discussion

  1. Sam

    Like in the terminal:

    cd -

    To return to the previously visited directory.

  2. Also useful when you want to merge the branch that you were just working on into dev/master (or any branch really)

    git checkout master
    git merge -
    

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!