checkout last branch
Sometimes you are checking out mutltiple different git branches and want to navigate back to previous branch.
You can use git checkout - to do it
example :
1
$ git checkout ay/convert-errors-lib
2
Updating files: 100% (2480/2480), done.
3
Switched to branch 'ay/convert-errors-lib'
4
​
5
$ git checkout -
6
Updating files: 100% (2480/2480), done.
7
Switched to branch 'master'
8
Your branch is up to date with 'origin/master'.
Copied!
If you want to checkout 2 branches a go. you can do
1
$ git checkout @{-2}
Copied!
Basically git checkout - is equql to git checkout @{-1}
If you want to list all of the checked out branch (history) you can use this script
1
$ for i in {1..10}; do echo -n "[$i] "; git rev-parse --symbolic-full-name @{-$i}; done
Copied!
I added this as a git command on my zsh. have a look at this commit​
Last modified 1mo ago
Copy link