Git/
Lesson

You understand the theory of Git workflows. Now it is time to put them into practice with real branching patterns that teams use every day. The difference between a smooth workflow and a chaotic one often comes down to how you name, create, and manage your branches.

A well-organized branching strategy is like a well-organized filing system. Anyone on the team can look at the branch list and immediately understand what is being worked on, what is ready for testing, and what is in production.

When you ask ChatGPT to help fix a production bug, it will often suggest making the fix directly on main and pushing. That advice ignores the entire review process. Even hotfixes should go through a branch and a PR, just with higher priority.

Branch naming conventions

Consistent naming is the first thing to establish. Here is the most common convention:

# Feature branches
feature/user-authentication
feature/search-bar
feature/payment-integration

# Bug fix branches
fix/login-null-pointer
fix/cart-total-calculation

# Hotfix branches (emergency production fixes)
hotfix/critical-auth-bypass
hotfix/payment-gateway-timeout

# Release branches
release/1.2.0
release/2.0.0-beta
PrefixWhen to useCreated fromMerges into
feature/New functionalitydevelop or maindevelop or main (via PR)
fix/Non-urgent bug fixesdevelop or maindevelop or main (via PR)
hotfix/Urgent production fixesmainmain + develop
release/Release preparationdevelopmain + develop
chore/Maintenance tasksdevelop or maindevelop or main (via PR)

Good branch names are lowercase, use hyphens to separate words, and are descriptive enough that anyone can understand the purpose without opening the code.

02

Feature branch lifecycle

A feature branch has a clear lifecycle from creation to deletion:

# 1. Create from the latest main (or develop)
git checkout main
git pull origin main
git checkout -b feature/user-profile

# 2. Work in small commits
git add src/components/Profile.jsx
git commit -m "feat: add profile component skeleton"

git add src/api/profile.js
git commit -m "feat: add profile API endpoints"

git add tests/profile.test.js
git commit -m "test: add profile component tests"

# 3. Keep your branch up to date with main
git fetch origin
git rebase origin/main
# Resolve any conflicts

# 4. Push and create a pull request
git push -u origin feature/user-profile

# 5. After PR approval and merge, delete the branch
git checkout main
git pull
git branch -d feature/user-profile
git push origin --delete feature/user-profile

The short-lived branch rule

Feature branches should live for days, not weeks. Long-lived branches accumulate merge conflicts and become increasingly difficult to review.

Branch ageConflict riskReview difficultyRecommendation
1-3 daysLowEasyIdeal
1 weekMediumManageableAcceptable
2+ weeksHighPainfulSplit into smaller branches
1+ monthVery highNearly impossibleRefactor your approach

If a feature takes more than a week, break it into smaller incremental PRs that can be merged independently.

03

Hotfix workflow

When production is down, you need a fast path to deploy a fix without waiting for the normal release process.

# 1. Create hotfix branch from main (production)
git checkout main
git pull
git checkout -b hotfix/critical-auth-fix

# 2. Fix the bug with minimal changes
git add src/auth.js
git commit -m "fix: prevent null pointer in session check"

# 3. Push and create an expedited PR
git push -u origin hotfix/critical-auth-fix
# PR review is faster for hotfixes, but still required

# 4. After merge to main, also merge into develop
git checkout develop
git merge main
git push

The key principle: hotfixes touch production code, so they must be small, focused, and reviewed. The review can be expedited (one reviewer instead of two), but never skipped entirely.

04

Release branch workflow

For teams using Git Flow, release branches provide a staging areaWhat is staging area?A holding zone in Git where you place changes you want to include in your next commit, letting you select exactly which modifications to save. between development and production:

# 1. Create release branch from develop
git checkout develop
git checkout -b release/1.2.0

# 2. Only bug fixes allowed on release branches
git commit -m "fix: correct date format in reports"
git commit -m "fix: handle empty cart edge case"

# 3. When ready, merge to main and tag
git checkout main
git merge release/1.2.0
git tag -a v1.2.0 -m "Release 1.2.0"
git push origin main --tags

# 4. Merge back to develop so fixes are not lost
git checkout develop
git merge release/1.2.0
git push

# 5. Delete the release branch
git branch -d release/1.2.0
AI will sometimes suggest tagging a commit on main without creating a release branch first. For small projects, that works. For teams with QA processes, release branches give testers a stable target while development continues on other features.
05

Cleaning up old branches

Stale branches clutter your repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.. Regularly clean up merged branches:

# List branches that have been merged into main
git branch --merged main

# Delete them locally
git branch -d feature/old-feature

# Delete them on the remote
git push origin --delete feature/old-feature

# Prune remote tracking references
git fetch --prune
06

Quick reference

TaskCommand
Create feature branchgit checkout -b feature/name
Keep branch updatedgit fetch origin && git rebase origin/main
Create hotfixgit checkout main && git checkout -b hotfix/name
Create releasegit checkout develop && git checkout -b release/x.y.z
Tag a releasegit tag -a v1.2.0 -m "Release 1.2.0"
Delete merged branchgit branch -d branch-name
Delete remote branchgit push origin --delete branch-name
Clean stale referencesgit fetch --prune