Did you know? Research improves critical thinking skills.

Git Branching Strategy explained

Git Branching Strategy

Git Branching Strategy

What is a Git Branching Strategy?

A Git branching strategy defines how developers create, use, and merge branches to manage code changes safely and efficiently.

1. Git Flow Branching Strategy

Main branches:

  • main → production-ready code
  • develop → integration branch

Supporting branches:

  • feature/* → new features
  • release/* → preparing release
  • hotfix/* → urgent production fix

Workflow Example:

git checkout develop
git checkout -b feature-login
# work done
git add .
git commit -m "Login feature"
git checkout develop
git merge feature-login
git checkout main
git merge develop
git push origin main

Best for: Large projects with scheduled releases.

2. GitHub Flow Branching Strategy

Main branch:

  • main → always stable

Workflow:

  • Create feature branch from main
  • Push branch to GitHub
  • Create Pull Request
  • Review and merge into main

Example:

git checkout -b feature-payment
git add .
git commit -m "Payment feature"
git push origin feature-payment
# Create Pull Request and merge to main

Best for: CI/CD and small to medium teams.

3. Trunk-Based Development

Main branch:

  • main (trunk) → only long-lived branch

Workflow:

  • Developers commit small changes frequently to main
  • Use feature flags instead of long-lived branches

Example:

git checkout main
git pull origin main
# small change
git add .
git commit -m "Small update"
git push origin main

Best for: High automation and fast delivery.

Comparison of Branching Strategies

Strategy Branches Complexity Best Use
Git Flow main, develop, feature, release, hotfix High Large enterprise projects
GitHub Flow main + feature Medium Web apps with CI/CD
Trunk-Based main only Low Microservices & fast release

Best Practices

  • Keep main branch stable
  • Use Pull Requests for merging
  • Write meaningful commit messages
  • Delete feature branches after merge
  • Use CI/CD for validation

Important Git Commands

ActionCommand
Create branchgit checkout -b branchname
Switch branchgit checkout branchname
Merge branchgit merge branchname
Delete branchgit branch -d branchname
Push branchgit push origin branchname
Pull latestgit pull origin main


Source: sureshtechlabs.com


Share this post:

WhatsApp Facebook Twitter Telegram