git provides an efficient shortcut to refer to a previous branch: “-”. It can be used to switch to a previous branch quickly or to merge current branch.

Let’s say you have two branches in your repo: master and new-feature where you work on the next big thing. If you switched from master to new-feature and now you want to switch back, just type:

# switch to the previous branch
git checkout -

and git will switch back to the master branch.

This is also useful for merging. If you want to merge the new-feature branch into the master you can just do the following:

# switch to from "feature" branch to "master" branch
git checkout master
# merge "new-feature" branch into the "master" branch
git merge -

In this case “merge -” is a shortcut for “merge a branch I’ve checked out from”.

This can require even less typing if you use oh-my-zsh extension for the zsh shell:

# switch to from the "new-feature" branch to the "master" branch
gco master
# merge the "new-feature" branch into the "master" branch
gm -


[feedzy-rss feeds="all-posts, syndication" ]