Matt Briggs Matt Briggs - 2 months ago 7x
Git Question

Is there any way to git checkout previous branch?

I sort of want the equivalent of

cd -
for git. If I am in branch
and I checkout
, I would love to be able to type something like
git checkout -
to go back to
, and be able to type it again to return to

Does anything like this exist? Would it be hard to implement?


From the release notes for 1.6.2

@{-1} is a way to refer to the last branch you were on. This is
accepted not only where an object name is expected, but anywhere a branch name is expected and acts as if you typed the branch name.
E.g. git branch --track mybranch @{-1}, git merge @{-1}, and
git rev-parse --symbolic-full-name @{-1} would work as expected.


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