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

  • By
    Create a Sheen Logo Effect with CSS

    I was inspired when I first saw Addy Osmani's original ShineTime blog post.  The hover sheen effect is simple but awesome.  When I started my blog redesign, I really wanted to use a sheen effect with my logo.  Using two HTML elements and...

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

Incredible Demos

  • By
    Degradable SELECT onChange

    Whenever I go to Google Analytics I notice a slight flicker in the dropdown list area. I see a button appear for the shortest amount of time and the poof! Gone. What that tells me is that Google is making their site function...

  • By
    Firefox Marketplace Animated Buttons

    The Firefox Marketplace is an incredibly attractive, easy to use hub that promises to make finding and promoting awesome HTML5-powered web applications easy and convenient. While I don't work directly on the Marketplace, I am privy to the codebase (and so...

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!