Git pushd & popd? I.e., checkout last state


I’m writing a Bash script, and I want to checkout a tag and then checkout back to where I started.

I tried git co [email protected]{1}, but when starting at master, that takes me back to the commit SHA of master but with a detatched head.

Is there something like pushd & popd for Git?


git checkout @{-1} which can be abbreviated to git checkout -.

From the manpage:

As a special case, the “@{-N}” syntax
for the N-th last branch checks out
the branch (instead of detaching). You
may also specify – which is synonymous
with “@{-1}”.

Answered By – wnoise

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published