Today I Learned

hashrocket A Hashrocket project

Git checkout to previous branches

In Git you can check out previous branches using @{-N}, where N is how many "branches ago" you want to go back.

For example, say you were in main then checked out branch-1 then checked out branch-2, and finally you checked out branch-3.

If you wanted to checkout the branch you were on "2 branches ago" you would just checkout @{-2}

> git checkout @{-2}
Switched to branch 'branch-1'

If you are using this to just go back to your previous branch @{-1}, there is a nice shortcut:

> git checkout -
Switched to branch 'branch-2'

H/T Matt Polito

See More #git TILs