We usually create a new branch in git repository, when we are working on a new project to be added into the codebase without affecting the current working code or when your current code has a bug and need to fix it on a testing server at such situation we simple create new branch git.
The best advantage in making a new git branch is that, we can alter our code & experiment with the codebase independently trial & error, without interfering with main codebase, then finally when testing is done and your git new branch work perfectly we can merge the changed of it to git main branch.
Additionally, By creating new branch in github repo allows your project team to freely test their own ideas & Implement new feature without the risk of breaking main branch codebase.
Git create branch
To make new branch in your github repository, run below commonds in root folder of your project:
git branch <branch-name>
Here, Replace ‘<branch-name>’, with a new branch name.
Example, I want to create a branch by my name “rajat-code”, use the below commands:
git branch rajat-code
This will create a branch by name “rajat-code”.
Note: The above cmd will simple create a new branch in git but will not automatically switch to new branch. To do so follow below step
git switch branch command
git checkout <branch-name>
Replace <branch-name> with you given new branch name.
git checkout rajat-code