Creating branches in Git

Creating branches in Git 1
Creating branches in Git 2

After the first initialization of our git repository, by default current branch will be the Master branch.

branches are a separate line of development within the same project. for example, you are developing a new feature for your application, but this feature should be available only to your pro customers, so you should make new two branches one for the free customers and other branches for the pro customers with pro features .now can develop on these both two branches and you can merge these two if you need to.

Create a branch from the current branch

 git branch  <branch name>

Checkout branch (switch branch)

git checkout <branch name>

Create and checkout at same time

git checkout -b <branch name>

mostly user create a branch and, they are ready to work on the new branch.instead of executing two commands for creating and switching to new brach, user can use the above command for performing two tasks

Create an existing branch by force

git branch --force <branch name>

If the user works on the development of the experimental branch and If he needs to change some code in the actual original code, the user should checkout to MASTER branch and edit changes

 git checkout master

List branches

git list

here, braches will be listed by the above command, HEAD pointer be indicated by the asterisk ( *)to the branch name in the list output.

Default image
Vishal Devxo
Vishal Devxo is a DevOps engineer and a Backend developer, he spends all his time for creating good tutorials with better visuals and blogging, developed some projects based on Python-Django, some hacking modules and scripts in python