DEV Community

Cover image for Branching in Git
Babilah
Babilah

Posted on

Branching in Git

So I have been learning git for some time now and I came across the topic of branches. I have learned so much from this topic, and would like to share with you what I learnt.

What is a Branch.

According to GitHub Glossary a branch is a parallel version of a repository. Branches are primarily used to create new features and once the feature is complete it is merged back into the master. By default git commits to the master branch. Git allows you to create , list, rename and delete branches.

Importance of Branches

  1. It allows you to clean up your futures hosting before merging it into the main branch.

  2. It allows unstable code to be managed before merging into the main code base.

Basic Git Branching commands

git branch

  • allows you to list all branches in your repository

git branch <branch-name>

  • allows you to create a new branch

git branch -d <branch-name>

  • deletes the specific branch also prevents you from deleting this branch if it has unmerged changes and it outputs an error.

git branch -D <branch-name>

  • deletes branch even if it has unmerged changes and does not out any error warnings.

git branch -m <branch-name>

  • renames the current branch

git branch -a

  • list all remote branches

git checkout

  • for switching between branches.

git merge

  • used to combine two branches usually a feature branch into a master branch

Conclusion

Branching in git is used to maintain code before they are merged to the master branch.
Branches helps enables to you to list branches, create new branches, delete branches and many more. In this article, you were taught the basis of how to work with branches.

Let me know in the comments if you have any contribution πŸ‘‡ or just leave a πŸ¦„ and share this post πŸ“£

Thanks for readingπŸ™

Top comments (0)