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
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • By
    Create a CSS Cube

    CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals.  Add animation and you've got something really neat.  Unfortunately each CSS cube tutorial I've read is a bit...

Incredible Demos

  • By
    dwImageProtector Plugin for jQuery

    I've always been curious about the jQuery JavaScript library. jQuery has captured the hearts of web designers and developers everywhere and I've always wondered why. I've been told it's easy, which is probably why designers were so quick to adopt it NOT that designers...

  • By
    Submit Button Enabling

    "Enabling" you ask? Yes. We all know how to disable the submit upon form submission and the reasons for doing so, but what about re-enabling the submit button after an allotted amount of time. After all, what if the user presses the "stop"...

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!