Create a Branch
What is Branches in Git ?
Git Branch is a new or separate version of main repository. A Git project can have more than one branch, branches create another line of development in the project. The primary or default branch in Git is the master branch.
Why we need branches ?
Branches are important because when you want to add a new feature or fix a bug, you create a new branch to summarize your changes.
Steps to create a new Branch -
We will see two method first with github UI & last with git commands-
First how you can create a branch with Github UI -
Step 1 :
Go to your Repositories and open that repo in which you want to create a new branch
step 2 :
When you open it you will see something like this.
step 3 :
When you click on main button you can see that you are currently on your default main branch
step 4 :
To create a new branch click on input box and type name of your branch and below you will see " Create Branch " just click on that
step 5 :
After clicking on create branch you will see a message on the top saying "Branch Created" and you automatically switched to new branch.
Done. You have sucessfully switched to the new branch, now you can start working in your new Branch 🎉
Second way to create a branch by using traditional command line -
Step 1 :
To create a new branch use this command
git branch <new_branch_name>
Step 2 :
After creating new branch, to list all of the branches use this command
git branch -a
Step 3 :
After creating a new branch you have to switch to the new branch for that use this command
git checkout <new_branch_name>