Thursday, January 30, 2025

Setting Up a Git Branching Strategy for Production and QA

Managing code effectively is critical for smooth software development and deployment. One effective way to achieve this is by setting up a structured Git branching strategy. In this guide, we will walk through how to set up separate Production and QA branches, ensuring code stability and seamless deployments.


Why Have Separate Production and QA Branches?

Having distinct branches for Production and QA offers several advantages:

  • ✅ Ensures code is tested in QA before going live.
  • ✅ Isolates development from production, reducing risks.
  • ✅ Allows hotfixes to be applied directly to production when necessary.
  • ✅ Provides a clear workflow for feature development, testing, and deployment.

1. Initial Setup: Creating the Main Branches

The first step is to set up the primary branches for production and quality assurance.

Create and push the main (Production) and qa (Testing) branches:

# Create production branch
git checkout -b main

# Create QA branch
git checkout -b qa

# Push branches to remote repository
git push -u origin main
git push -u origin qa

2. Working with Feature Branches

Developers should create feature branches from qa, ensuring all development work is tested before merging into production.

Create and work on a new feature branch

git checkout -b feature/new-feature qa   # Create feature branch from QA
# Work on the feature, then stage and commit

git add .
git commit -m "Added new feature"
git push -u origin feature/new-feature

Merge the feature branch into qa after testing

git checkout qa
git pull origin qa
git merge feature/new-feature
git push origin qa

3. Preparing for Production

After QA approval, code should be merged from qa to main for production deployment.

Merge qa into main

git checkout main
git pull origin main
git merge qa
git push origin main

Tagging a release (optional but recommended)

git tag -a v1.0 -m "Release version 1.0"
git push origin v1.0

4. Handling Hotfixes for Production

If a critical issue is discovered in production, it's best to create a hotfix branch directly from main.

Create a hotfix branch

git checkout -b hotfix/critical-fix main
# Fix the issue, then commit and push
git add .
git commit -m "Fixed critical bug"
git push -u origin hotfix/critical-fix

Merge the hotfix into main and qa

git checkout main
git merge hotfix/critical-fix
git push origin main

git checkout qa
git merge hotfix/critical-fix
git push origin qa

5. Keeping qa Updated with main

To ensure that qa always reflects the latest production changes, merge main into qa regularly.

git checkout qa
git merge main
git push origin qa

Summary of the Workflow

  1. Developers create feature branches from qa.
  2. Merge feature branches into qa after development.
  3. QA team tests the qa branch and approves changes.
  4. Merge qa into main for production release.
  5. Hotfixes go directly into main, then get merged back to qa.

With this approach, your code remains stable, development is structured, and deployments are smooth.

No comments:

Post a Comment