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)