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)
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)$
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)
PLEASE FOLLOW, LIKE, SHARE, AND COMMENT
You should also check:

8 JavaScript Tips & Tricks That No One Teaches 🚀
Garvit Motwani ・ Apr 6 ・ 3 min read

250+ JS Resources to Master Programming 💥 Cheat Sheet
DevLorenzo ・ Apr 20 ・ 19 min read

6 Python Tips & Tricks that no One Teaches 🚀🐍
Daniel Diaz ・ Apr 26 ・ 5 min read
Subscribe to our newsletter
Top comments (0)