DEV Community

Quickly Switching Between Two Branches in Git

Claire Parker-Jones on June 08, 2018

git checkout - checks out the last branch you were working on. Do you find yourself needing to switch between the same two branches in git again...
Collapse
 
jess profile image
Jess Lee • Edited

haha yes! good trick. @maestromac taught me that a few months ago :)

Collapse
 
jrop profile image
Jonathan Apodaca

Also look into git worktrees if you want to keep two or more branches checked out at the same time.

Collapse
 
jandedobbeleer profile image
Jan De Dobbeleer • Edited

That one is very well kept secret though. Used it on various occasions when stashing wasn't interesting.

Collapse
 
andrekelvin profile image
AndreKelvin

Noted

Collapse
 
thehanna profile image
Brian Hanna

This also works for the cd command. It takes you to the previous directory.

Collapse
 
pardhabilla profile image
pardha-billa

Good Trick!!