Skip to content

Switch Between Two Git Branches – Quickest Way!

Switch Between Two Git Branches the Quickest Way

Usually, when you want to switch branches, you use git checkout branch-name.

But let’s say you’re working with two branches and want a quick way to switch between them.

You wouldn’t want to type the name of the branch every time you want to switch to it.

That’s where the git checkout - comes in.

Let’s see how it works.

How does git checkout - work?

The git checkout - command allows you to switch to the previous branch you were on.

  • Let’s say you are currently on branch-A.
  • You run git checkout branch-B to switch to it
  • After working on branch-B you decide to switch back to branch-A, but you don’t remember the branch’s name or you just want to save a bunch of keystrokes
  • So you type git checkout - which will take you back to the last branch you were in before switching to branch-B. In this case, branch-A.

Essentially, git checkout - toggles between two branches: the current one and the branch you were in before the most recent branch switch.

🎥 Check out this video for a showcase of this functionality:



Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.   
  

Comments

Tags: