How to Checkout the Previous Branch in Git

Sometimes, I forget the last branch name with how many branches I jump between.

Here's a simple way to switch to your previous branch in Git.

git checkout -

Or another way:

git checkout @{-1}

This second one is handy because you can use it to checkout N-th last branch/commit. So if you wanted to checkout 3 branches ago you could use:

git checkout @{-3}

I use the second way mostly because I find the @{-N} very useful (and it's a built-in reflex of mine now).

Command LineQuick TipsGitTerminal
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.