In Git, a branch is a new/separate version of the main repository.
Branches allow you to work on different parts of a project without impacting the main branch. When the work is complete, a branch can be merged with the main project.
We can even switch between branches and work on different projects without them interfering with each other.
New Git Branch
1
git branch <name of branch>
Check All Branches
1
git branch
Switching to other branches
1
git checkout <branch name>
Making a new branch and directly switching to it
1
git checkout -b <branch name>
Deleting a branch
1
git branch -d <branch name>
Merging two branches
- It’s preferred to change/switch to master branch before any branch needs to be merged with it.
1
git merge <branch name>
- This will merge the specified branch with our master branch.