Get "PHP 8 in a Nuthshell" (Soon includes PHP 8.4)
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!

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?