Is there any way to get back to the last branch in git?

Asked

Viewed 90 times

4

The title says it all. Around and a half we use the git as follows:

git checkout branch_x
git checkout branch_y
git checkout branch_x

x can be master, or some Feature branch whichever.

I wonder if there’s any way back to the last branch used. git has something equivalent to cd - for directories on the command line?

1 answer

4


I believe it is enough to do the following at the command line:

git checkout @{-1}

As exemplified in these answers.

  • Opa, by another answer on that same link I discovered that git checkout - also works in relatively modern versions of Git. Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.