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.

git branch meme

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:

git bash here menu option

Now when your git bash terminal is open, it might look something like this. Ignore all the stuff I have hidden.

git bash terminal

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:

how to create a new branch using git

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.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

1 Response

  1. March 30, 2020

    […] 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 […]

Leave a Reply