Last Updated: February 25, 2016
·
338
· bugthing

Switch to the previous branch in git

If you use git and change between branches often, you'll certainly find this handy

git checkout -

The above command will checkout the previous branch you were on.

Lets see an example. If you were to checkout a feature branch like so:

git checkout feature/my_super_new_thingy_what_I_done

Then change to another branch

git checkout master

To get back to the feature branch, you simply have to do

git checkout -

I like it because I dont have to remember the previous branch name (or go on a scroll hunt looking for it in my buffers)