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:
![garvitmotwani image](https://res.cloudinary.com/practicaldev/image/fetch/s--1xnkyVuI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--0F4scheH--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/370225/60416eff-f1ff-4a29-a5c9-2a13df7845c8.jpeg)
8 JavaScript Tips & Tricks That No One Teaches π
Garvit Motwani γ» Apr 6 γ» 3 min read
![devlorenzo image](https://res.cloudinary.com/practicaldev/image/fetch/s--pCohWvfe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--8B-BJEvg--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_66%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/571015/e3d4ff5f-e11d-4538-bb83-9d3ce3e9dfb9.gif)
250+ JS Resources to Master Programming π₯ Cheat Sheet
DevLorenzo γ» Apr 20 γ» 19 min read
![daniel1404 image](https://res.cloudinary.com/practicaldev/image/fetch/s--YKr9I-E---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--hBgYP-SM--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/547275/e6dab600-34b7-49e0-a884-eb975de66405.png)
6 Python Tips & Tricks that no One Teaches ππ
Daniel Diaz γ» Apr 26 γ» 5 min read
Subscribe to our newsletter
Top comments (0)