Android App

TechLogic

Why should you follow naming conventions when naming your branch on Git?


Basically, Branches in git (which is a distributed version control system) are pointers to certain nodes in the DAG tree of commits. They will move when you perform some operations (e.g. a commit). ‘master’ is one such pointer which is by default the one created when you initialise a fresh repository.
First of all, let’s check what kind of things we generally do in our code base:
  • Updating a page, screen, view, feature
  • Adding a new feature, new page, etc
  • Adding a new library, plugin or framework, dependency
  • Adding unit test, hooks, etc
  • Fixing bug or broken feature, flow, etc
  • Upgrading a dependency, plugin or framework
  • Removing or undoing any of the above
Branches are supposed to be transient — as long as the branch names are unique enough that people aren't conflicting, I don't see the problem with giving any branch name to your any branches. You can name your branch whatever you feel like. But, Let’s see some benefits of following naming conventions for branch on Git—
    1. The basic benefit would be that if people actually name it to what it actually is or does, you don't need to read the entire code base to figure this out, hence saving even more time.
    2. If you look at all the following branch names (which follows some naming conventions) they would be much more uniform and pleasant to look at. Also, you can easily understand what they belongs to or what they actually do in code. Prefix mentioned in branch name may help you to identify behaviour of your branch. e.g a branch with prefix “junk” is only for test and not for merge.
  1. feature/quora-app-new-feature
  2. feature/quora-app-documentation
  3. feature/quora-app-new-page
  4.  
  5. fix/quora-app-documentation-refactor
  6.  
  7. fix/quora-app-hotfix
  8. fix/quora-app-ui-bugfix
  9. patch/quora-app-hotfix-patch
  10. junk/quora-trial-for-something-not-to-merge
     3. Some popular Branch names:
  1. master = current state of the live site
  2.  
  3. develop = stable development environment that keeps all developers in sync.
  4.  
  5. feature/feature-name = unstable new features under development or refactoring that might break the site.
  6.  
  7. hotfix = fixing a critical bug on the live site.
  8.  
  9. release/release-name-with-or-without-version = release of developed features on the site with release version for more specific, tracking.

So, having meaningful branch names is always good as a courtesy to yourself and others. Following naming convention for branch names will definitely add consistency, better understanding, readability, consistency throughout the project and team. Thats’s why many developers and/or teams are adding some pre-commit hooks to validate naming convention of branch.
(This post was originally written as answer on Quora.com)




Post a Comment