Git Branching Strategy & Workflow
Overview
This document outlines our Git branching strategy and automated workflows. Our approach is designed to:
- Identify integration issues early
- Maintain clean release pipelines
- Provide clear visibility into the release process
- Minimize manual conflict resolution
Branch Structure
We use the following branch hierarchy:
Branch | Purpose | Protection | Merge Strategy |
---|---|---|---|
master |
Production code | ✅ | Merge via PR from release branches only |
staging |
Pre-release testing | ✅ | Merge via PR from dev |
dev |
Integration testing | ✅ | Auto-merge from feature branches |
Feature branches | Development | ❌ | Direct push |
Synchronization Process
Our branches stay in sync through automated rebase operations:
- Daily:
staging
rebases ontomaster
to incorporate hotfixes - Daily:
dev
rebases ontostaging
to stay current with pending releases - This automated process creates PRs and alerts the team to conflicts that require manual resolution
Working with Feature Branches
Branch Naming
Use descriptive prefixes for your branch names:
feature/
- New featuresfix/
- Bug fixeschore/
- Maintenance tasksdocs/
- Documentation updatesrefactor/
- Code refactoringtest/
- Test-related changes
Example: feature/add-user-authentication
Development Workflow
- Create a branch from
dev
:
- Make your changes on the feature branch:
- Push your branch to GitHub:
-
Automatic Integration:
-
When you push to a feature branch, GitHub Actions will automatically:
- Run the build and tests
- Create a PR to merge your branch into
dev
-
Keep your branch up to date with
dev
:
Promoting to Staging and Production
Dev to Staging (Feature Release)
When ready to prepare a release:
- Create a PR from
dev
tostaging
- Complete thorough QA in the staging environment
- Get required approvals
- Merge the PR
Staging to Master (Production Release)
To promote to production:
- Navigate to GitHub Actions
- Run the "Release Promotion" workflow
- Input the release version (e.g.,
v1.2.3
) - Optionally add release notes
- The workflow will:
- Create a release branch from staging
- Create a PR to master
- Create a draft GitHub release
- After final approval, merge the PR to master
- Publish the GitHub release
Handling Conflicts
When the automatic rebase process detects conflicts:
- GitHub Actions will create a PR with conflicts marked
- Team members (usually leads) resolve conflicts manually
- Once resolved, the PR can be approved and merged
Emergency Hotfixes
For urgent production fixes:
- Create a branch from
master
namedhotfix/description
- Make and test your changes
- Create a PR directly to
master
- After approval and merge, create a PR to backport the fix to
staging
anddev
GitHub Actions Workflows
Branch Synchronization
The branch-sync.yml
workflow runs:
- Automatically every day at midnight UTC
- Manually when triggered by a team member
It creates PRs for:
- Rebasing
staging
ontomaster
- Rebasing
dev
ontostaging
Feature Branch Integration
The feature-to-dev.yml
workflow runs:
- Automatically on pushes to feature branches
- Manually when triggered with a specified branch
It runs tests and creates PRs to merge feature branches into dev
.
Release Promotion
The release-promotion.yml
workflow:
- Must be manually triggered
- Allows specifying a version number and release notes
- Creates a release branch from
staging
- Creates a PR to merge the release branch into
master
- Prepares a draft GitHub release
GitHub Repository Settings
Ensure the repository has these settings configured:
-
Branch Protection for
master
: -
Require pull request reviews before merging
- Require status checks to pass
-
Restrict who can push to matching branches
-
Branch Protection for
staging
: -
Require pull request reviews before merging
-
Require status checks to pass
-
Branch Protection for
dev
: -
Require status checks to pass
-
Required Status Checks:
- build-and-test job from CI workflow
Required GitHub Secrets
For these workflows to function properly, you need to set up these repository secrets:
BRANCH_SYNC_PAT
: A GitHub Personal Access Token with repo permissions for branch synchronizationRELEASE_PAT
: A GitHub Personal Access Token with repo permissions for release management
Need Help?
Contact the DevOps team for questions about this workflow or to report issues with the automated processes. No newline at end of file