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!!
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)
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)$
There is a shortcut to return the previous branch you were in, you can just use
(master)$ git checkout - Switched to branch 'new-branch' $ (new-branch)
PLEASE FOLLOW, LIKE, SHARE, AND COMMENT
You should also check:
Subscribe to our newsletter