All About Switching Branch In Git 🚀
Garvit Motwani

Garvit Motwani @garvitmotwani

About: Web Developer 👨‍🎓 13 👨‍💻 HTML, CSS, JavaScript, ReactJS

Location:
Indore, India
Joined:
Apr 20, 2020

All About Switching Branch In Git 🚀

Publish Date: May 8 '21
13 0

Whether you're an open-source contributor, project manager, or even a normal github user for personal projects maybe, you need to know how to Switch Branches In Git.

So let's get started!!

How to create a new branch

Normally you use git checkout with a -b flag and pass a name for the branch.

If you are on the branch called master, this will be the case for you:

$ (master) git checkout -b new-branch
Switched to a new branch 'new-branch'
$ (new-branch)
Enter fullscreen mode Exit fullscreen mode

How to switch to an existing branch

To switch to an existing branch, you can use git checkout but without the -b flag and pass the name of the branch you want to switch to, something like this:

(new-branch)$ git checkout master
Switched to branch 'master'
(master)$
Enter fullscreen mode Exit fullscreen mode

Bonus:

There is a shortcut to return the previous branch you were in, you can just use - after git checkout

(master)$ git checkout -
Switched to branch 'new-branch'
$ (new-branch)
Enter fullscreen mode Exit fullscreen mode

PLEASE FOLLOW, LIKE, SHARE, AND COMMENT

Follow me on Dev and Twitter

You should also check:

Subscribe to our newsletter

Comments 0 total

    Add comment