How to Create a new Branch in Git
This little post is on how to create a new branch using Git. Pretty fair and simple, I know. But a lot of people still don’t know this. And I have decided to help those poor creatures out.
Git could be a tricky world. There are so many commands to learn in here, that I can understand how you could tend to forget even the simplest of ones.
Here’s the way you can create a branch in Git:
Steps on How to Create a new Branch using Git
I am assuming you have your git bash open. You can do so by navigating to the repository you are in, and simply right clicking and then doing Git Bash Here as shown below:
Now when your git bash terminal is open, it might look something like this. Ignore all the stuff I have hidden.
Ensure you are on the master. If you are not you can always do the following to navigate to the master branch.
git checkout master
Then you just have to type the following command in order to create a new branch on the terminal.
git checkout -b <branch_name>
where replace <branch_name> with the name of the branch you want.
Here’s an example for the above:
So all I did was type the above and press enter.
If you notice the right side of the directory info now says the name of your branch in brackets () instead of master.
That means you have already navigated to the new branch.
So that’s how you create a new branch in Git. Pretty straightforward, right?
So here’s an exercise for you guys. Now that you have created this branch, show me how you delete it.
But you know what there is a fairly simple way to create a new branch if you are using Visual Studio Code or VSC.
Here’s a tutorial on how to do that. You can thank me later.
1 Response
[…] that I don’t know a piece of cake? Well, creating a new branch using Git is even easier, because basically that is just one piece of […]