Fundamentals 12 min read

Git Workflow, Branch Naming, and Commit Standards: Best Practices and Tooling

This article explains comprehensive Git workflow, branch naming conventions, commit message standards, and supporting tools such as validate-branch-name, Husky, Commitizen, and Commitlint, providing practical examples and configuration snippets to help development teams maintain a clean and efficient version‑control process.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Git Workflow, Branch Naming, and Commit Standards: Best Practices and Tooling

When a new project encounters confusing Git history with branches like task/10001 , hotfix/0910 , and commit messages such as 实现10001需求 , the author proposes a formal Git standard to improve readability and traceability.

The recommended workflow uses two long‑living branches: main for production releases (e.g., tags v1.0 , v2.0 ) and develop for continuous integration. Feature development occurs on feature/* branches, which are merged into develop . When a release is ready, a release/x.y.z branch is created from develop ; after testing, it is merged into both main and develop . Hotfixes are created directly from main and merged back to both main and develop .

Branch naming follows clear prefixes:

feat : new features (e.g., feat/1000-list-dynamic-loading )

fix : bug fixes (e.g., fix/2000-list-style-align )

perf : performance improvements (e.g., perf/list-memory-occupation )

refactor : structural changes (e.g., refactor/modules-to-packages )

chore : auxiliary tasks (e.g., chore/eslint-upgrade )

To enforce naming rules, the validate-branch-name tool can be installed globally:

npm i validate-branch-name -g

and added to a .husky pre‑commit hook:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# validate branch name before commit
npx validate-branch-name

The tool’s configuration in package.json looks like:

"validate-branch-name": {
  "pattern": "^(master|main|develop){1}$|^(feat|fix|hotfix|release|perf|refactor|chore)/.+$",
  "errorMsg": "分支命名不规范,请修正!"
}

Additional commit‑message enforcement is achieved with Husky, Commitizen, and Commitlint. Install Husky:

npx husky-init && npm install

Install and configure commitizen with the cz-conventional-changelog adapter:

npm install commitizen --save-dev
commitizen init cz-conventional-changelog --save-dev --save-exact

Install Commitlint and add a commitlint.config.js file:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  parserPreset: {
    parserOpts: {
      issuePrefixes: ['#'],
    },
  },
};

Hook the validation into Git via Husky:

npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'

Finally, add a prepare-commit-msg hook to launch the interactive Commitizen prompt:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
exec < /dev/tty && npx cz --hook || true

In summary, a solid Git standard covers workflow, branch naming, and commit conventions, supported by tools that automate validation and provide interactive guidance, thereby improving codebase readability, reducing troubleshooting time, and enhancing overall development efficiency.

workflowDevOpsgittoolscommitbranch-naming
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.