The git branch command defines a new collection in the line of the current development, which means another direction contains a new pointer in the development.

The git branch command can do 3 actions, which are:

Anyway, the default branch of GIT called “master”. So if you didn’t define branches before on your project, you have to use the “master” branch as default integration.

what does git branch command do

So, let’s focus on each one in-depth. Firstly, I am going to explain how to define a new branch for the current repository.

How to Insert a New Branch Using Git

As I mentioned before, there is a default branch name in GIT called “master”. If you need to add a new one, you have to use the following command.

git branch [new-branch-name]

This command only creating a new branch without switching from the old branch.

So, when you define a new branch, that means the next commits will be added there just when you refer to the branch name through the git commands.

Anyway, to rename the current branch, you have to use the following one.

git branch -m [new-branch-name]

In the following section, I am going to cover another action in git branch to remove the selected branch from the git remote system.

How to Remove an Existing Branch Using Git

It is so easy to remove an existing branch using git branch. You only have to use the following command.

git branch -d [branch-name]

This command will remove the specified branch name from the track.

Also, there is another way to force deletion. Just use the following to permanently remove action.

git branch -D [branch-name]

These two commands only removing the branch on the local repository, So to remove the remote branch you have to run the following command.

git push origin :[branch-name]

And you can do that with another command else.

git push origin –delete [branch-name]

In the next section, I am going to display you how to display all branches in the current project using git command.

How to Display All Existing Branches Using Git

To all branches in the current project, you have only you to run the following command.

git branch -a

In the next section, you will learn how to switch from the old branch into the new branch.

How to Switch from Current Branch to another Branch using git?

To move the pointer to another existing branch, you can run the following command.

git switch [branch-name]

Wrapping Up

In this article, you learned how to insert a new branch using git branch command and also learned how to remove, rename, list branches and switching into a new branch using a few commands.

That’s all, thank you for reading. Stay tuned for my next articles.