Quick Switch Between Git Branches

Today’s little-known git feature (or maybe everyone knows but me? I only found this a few months ago) is for quickly switching between branches. Usually I would switch branches with:

git checkout [branchname]

However if you switch from one branch to another and want to switch back again (this happens when I’m reviewing changes and wondering if a bug is present on master as well), then you can do so by just doing:

git checkout -

Just a little timesaver in case it’s useful to anyone else – I know I’ve been using it quite a bit!

4 thoughts on “Quick Switch Between Git Branches

  1. Pingback: Quick Switch Between Git Branches | Advanced PH...

  2. This is great. Thanks for sharing. My team has decided to use painfully verbose and meaningful branch names.

    This will be easy for me to remember too; it’s just like “fg -” in bash job control.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.