Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

The fastest way to switch between two branches in Git

This is something you might already be aware of but if you’re using Git on your terminal, there’s a faster way to switch between two branches using the checkout command.

Here’s the command.

git checkout -

The command above will switch you to the last branch you were on. So, for instance, if you were on the master branch and you switched to the develop branch, running the command above will switch you back to the master branch.

And if you want to switch back to the develop branch, you can run the same command again.

Switching between branches using git checkout -

Trust me, this saves a lot of time and keystrokes.

And while we’re at it, you can also cd-ing between recent directories using a similar command.

cd -

Again, a very handy one!

👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I do and want me to continue doing the same, I'd like you consider leaving a tip. I'd highly appreciate that. Cheers!