Comprehensive Guide to Git Branching Model and Workflow for Enterprise Development
This article provides a detailed, step‑by‑step tutorial on enterprise‑grade Git branching models, development processes, common commands, merge strategies, troubleshooting tips, and advanced techniques such as cherry‑pick and rebase, helping newcomers and teams adopt a reliable version‑control workflow.
1. Development Branch Model Classification
The typical branch hierarchy in the described department includes four main branches: dev (development), test (testing), uat (pre‑release), and release (production). Small teams may only use dev and master .
2. Core Development Process
Requirement review
Development scheduling
Code implementation
Smoke testing (self‑validation)
Merge to test branch and deploy to test environment
Test‑environment testing and bug fixing
Merge to UAT branch and deploy to UAT
UAT testing and bug fixing
Product acceptance
Merge to release branch and deploy to production
Customer acceptance
Project closure
3. Specific Operations
3.1 Pulling Code
git clone https://code.xxx.com/xxx/xxx.git3.2 Creating a Feature Branch from Release/UAT
git fetch origin release:release
git checkout release
git checkout -b feat-0131-jieIf the release branch already exists locally, update it first:
# small tip: you can tab‑complete branch names
git checkout release
git pull origin release
git checkout -b feat-0229-jieBranch naming convention
Use a format such as type‑date/ID‑author , e.g., feat for new features, fix for bug fixes, doc for documentation, refactor for refactoring, test for tests, and chore for auxiliary tasks.
3.3 Committing and Merging
Commit with a message that mirrors the branch name, e.g., feat: 0131‑Add billing period or fix: ZenTao3387‑Duplicate request :
git add .
git commit -m "commit description"Before merging, ensure each branch contains only one logical change. Merge into the appropriate environment branch (dev, test, uat, release) and never merge higher‑level branches back into lower‑level ones.
Online merge (recommended)
git push origin feat-0131-jieOpen a merge request on the remote repository, target the appropriate environment branch, resolve conflicts online, and complete the merge.
Local merge (requires push permission)
# switch to the target environment branch
git fetch origin test:test
git checkout test
# merge feature branch and resolve conflicts locally
git merge feat-0131-jie
# push the updated environment branch
git push origin testOnline merges reduce local conflict risk, improve code review, and enhance traceability.
3.4 Deleting Finished Branches
git branch -d <branch-name>
# force delete if needed
git branch -D <branch-name>4. Common Issues
4.1 Why re‑test bugs after fixing in UAT?
UAT simulates production; re‑testing ensures the fix does not introduce new issues before promotion.
4.2 Reverting an Incorrect Merge that was Pushed
git checkout release
git log --merges
git revert -m 1 <merge‑commit‑ID>
git push -f origin release4.3 Stashing Uncommitted Changes to Switch Branches
git stash
git checkout feat-a-jie
# after work
git checkout feat-b-jie
git stash pop5. Advanced Commands
5.1 cherry‑pick
Select specific commits to apply onto the current branch:
# view recent commits
git log
# switch to target branch
git checkout test
# apply a commit
git cherry-pick <commitHash>5.2 rebase
Rewrite history by moving a branch’s commits onto another branch’s tip, creating a linear history. Never rebase a shared branch.
6. Popular Git Workflow Models
Git Flow
GitHub Flow
GitLab Flow (the workflow described in this article)
Adopting a consistent workflow improves collaboration, reduces conflicts, and supports continuous integration and delivery.
7. Conclusion
Git has evolved for nearly two decades, spawning countless tools and conventions. The practices presented here are a pragmatic subset suitable for newcomers and small teams, emphasizing clear branch structures, naming conventions, and disciplined merge strategies to boost productivity and code quality.
Rare Earth Juejin Tech Community
Juejin, a tech community that helps developers grow.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.