DevOps Zone is brought to you in partnership with:

Lorna Jane Mitchell is a PHP developer, blogger, trainer and evangelist from Leeds in the UK. She is active with phpwomen.org and her local user group PHP North West, and writes for a variety of outlets, including her own blog at lornajane.net. She is an active member of the PHP and open source communities and contributes to the joind.in event feedback project. When she's not at her computer, Lorna enjoys yarn craft, hobby electronics, and her home renovation project. Lorna is a DZone MVB and is not an employee of DZone and has posted 82 posts at DZone. You can read more from them at their website. View Full User Profile

Quick Switch Between Git Branches

03.31.2014
| 7759 views |
  • submit to reddit

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!

Published at DZone with permission of Lorna Mitchell, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Martin Knoller ... replied on Mon, 2014/03/31 - 7:32am

This works also for merging, which I find rather creepy:

git merge -

Paul Fife replied on Thu, 2014/04/03 - 9:03am in response to: Martin Knoller Stocker

For merging it makes sense for some workflows. eg.

- commit changes to one branch

- switch to another to merge to

- use git merge - to merge from previous

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.