Master proven Git collaboration strategies to enhance team productivity, code quality, and release management.
A Git workflow is a recipe or recommendation for how to use Git to accomplish work in a consistent and productive manner. Workflows are guidelines rather than concrete rules, designed to:
- Coordinate team collaboration
- Ensure code quality and stability
- Streamline development and release processes
- Prevent conflicts during integration
- Maintain a clean, logical project history
When selecting a workflow, consider:
- Team size and experience with Git
- Project complexity and release frequency
- Deployment requirements
- Integration with existing processes (CI/CD, reviews, etc.)
- Need for supporting multiple production versions
Most Git workflows share these core elements:
┌───────────────┐ ┌────────────────┐ ┌────────────────┐
│ Branch Model │ ──▶ │ Integration │ ──▶ │ Release │
│ How code │ │ Strategy │ │ Process │
│ changes flow │ │ How changes │ │ How to deploy │
└───────────────┘ │ are combined │ │ and version │
└────────────────┘ └────────────────┘
The Centralized Workflow uses a single main branch as the central repository for all changes, similar to traditional version control systems like SVN.
Best suited for:
- Teams transitioning from SVN or other centralized VCS
- Small teams with simple projects
- Projects with minimal parallel development
Visual representation:
main: A---B---C---D---E---F---G
↑ ↑
Alice's Bob's
change change
Create/clone the central repository:
# Initialize central repo (once)
git init --bare central-project.git
# Each developer clones the repo
git clone central-project.gitMake local changes:
# Edit files locally
git add changed-files
git commit -m "Description of changes"Synchronize with central repository:
# Get latest changes
git pull origin main
# Push local commits
git push origin mainResolve conflicts if necessary:
# When pull fails due to conflicts
git pull origin main
# Resolve conflicts manually
git add resolved-files
git commit -m "Merge and resolve conflicts"
git push origin mainAdvantages:
- Simplest workflow to understand and implement
- Minimal branch management overhead
- Linear history is easy to follow
Limitations:
- No isolated environments for feature development
- Higher chance of merge conflicts
- Lack of formal code review mechanism
- Harder to maintain stable production code
- Pull frequently to minimize merge conflicts
- Communicate with team members before making significant changes
- Consider using feature branches for larger changes
- Add good commit messages to maintain a usable history
The Feature Branch Workflow extends the Centralized Workflow by developing all features in dedicated branches instead of directly on main. This isolates new development, enabling pull requests and code reviews.
Best suited for:
- Most professional teams
- Projects with multiple developers working in parallel
- Codebases requiring code reviews before integration
Visual representation:
main: A---B---C------------D---F
\ / /
feature-1: D---E------/ /
/
feature-2: G---H----/
Create a feature branch:
# Update main first
git checkout main
git pull origin main
# Create feature branch
git checkout -b feature/user-authenticationWork on the feature:
# Make changes
git add changed-files
git commit -m "Implement login form"
# Continue development with multiple commits
git add more-files
git commit -m "Add password validation"Push feature branch to remote:
git push -u origin feature/user-authenticationCreate pull request (via GitHub/GitLab/etc.)
Review and merge:
# After approval, merge to main
git checkout main
git pull origin main
git merge feature/user-authentication
git push origin main
# Or use the platform's merge buttonCleanup:
# Delete the local branch
git branch -d feature/user-authentication
# Delete the remote branch
git push origin --delete feature/user-authenticationConsistent branch naming improves workflow clarity:
<type>/<description>
Common types:
feature/- New functionalitybugfix/- Bug fixeshotfix/- Critical fixes for productionrelease/- Release preparationrefactor/- Code improvements without feature changesdocs/- Documentation changestest/- Test additions or corrections
Examples:
feature/user-authenticationbugfix/login-validationhotfix/security-vulnerabilityrelease/v1.2.0
A typical pull request workflow:
- Developer creates PR with description of changes
- CI runs automated tests
- Team members review code and provide feedback
- Developer addresses feedback with follow-up commits
- PR is approved by required reviewers
- PR is merged (merge, squash, or rebase)
Effective code reviews focus on:
- Code correctness and edge cases
- Test coverage
- Performance implications
- Security considerations
- Adherence to project style and standards
- Documentation completeness
💡 Tip: Aim for small, focused PRs to make reviews more manageable and effective.
Gitflow is a robust framework for managing larger projects with scheduled releases. It uses dedicated branches for features, releases, and hotfixes with strict conventions about how changes flow between them.
Best suited for:
- Larger teams with formal release processes
- Projects with multiple versions in production
- Software with scheduled release cycles
Visual representation:
hotfix/1.0.1
|
v
main: A-------M------P------T
\ \ \ \
develop: B---C---N---O--Q---R--U
/ /\
feature/1: D---E---F--/ \
\ \
feature/2: G---H
\
release/1.0: I---J---K
Gitflow defines specific branches with different roles:
| Branch Type | Base Branch | Naming | Merges Into | Purpose |
|---|---|---|---|---|
main |
- | main |
- | Production-ready code |
develop |
main |
develop |
- | Integration branch for features |
feature |
develop |
feature/* |
develop |
New functionality development |
release |
develop |
release/* |
main & develop |
Release preparation & stabilization |
hotfix |
main |
hotfix/* |
main & develop |
Emergency production fixes |
Setup Gitflow:
# Initialize repository with Gitflow
git flow init -d
# Or manually create required branches
git branch develop
git push -u origin developStart a feature:
# Using gitflow extension
git flow feature start user-authentication
# Or manually
git checkout develop
git checkout -b feature/user-authenticationFinish a feature:
# Using gitflow extension
git flow feature finish user-authentication
# Or manually
git checkout develop
git merge --no-ff feature/user-authentication
git branch -d feature/user-authenticationStart a release:
# Using gitflow extension
git flow release start 1.2.0
# Or manually
git checkout develop
git checkout -b release/1.2.0Finish a release:
# Using gitflow extension
git flow release finish 1.2.0
# Or manually
git checkout main
git merge --no-ff release/1.2.0
git tag -a v1.2.0 -m "Version 1.2.0"
git checkout develop
git merge --no-ff release/1.2.0
git branch -d release/1.2.0Create and finish a hotfix:
# Using gitflow extension
git flow hotfix start 1.2.1
# Or manually
git checkout main
git checkout -b hotfix/1.2.1
# When finished with gitflow
git flow hotfix finish 1.2.1
# Or manually
git checkout main
git merge --no-ff hotfix/1.2.1
git tag -a v1.2.1 -m "Version 1.2.1"
git checkout develop
git merge --no-ff hotfix/1.2.1
git branch -d hotfix/1.2.1The release process in Gitflow:
- Create a release branch from
develop - Make release-specific changes (version numbers, etc.)
- Bug fixes for the release go directly to release branch
- When stable, merge into
mainand tag with version number - Also merge back into
developto incorporate release fixes - Delete the release branch
The hotfix process in Gitflow:
- Create hotfix branch from
main - Fix the critical issue
- Merge into both
mainanddevelop(or active release branch) - Tag the
mainmerge with updated version number - Delete the hotfix branch
The Gitflow workflow can be implemented manually or using dedicated tools:
# Install the gitflow extension
# macOS
brew install git-flow-avh
# Windows (with Git for Windows)
# Already included
# Linux
apt-get install git-flowCommon gitflow commands:
git flow init # Set up repo for gitflow
git flow feature start # Start a feature branch
git flow feature finish # Finish a feature branch
git flow release start # Start a release branch
git flow release finish # Finish a release branch
git flow hotfix start # Start a hotfix branch
git flow hotfix finish # Finish a hotfix branchThe Forking Workflow is unique in that each developer has their own server-side repository. This means every developer has two Git repositories: a private local one and a public server-side one.
Best suited for:
- Open source projects
- Large public projects with many contributors
- Projects where contributors don't have write access to the main repository
Visual representation:
upstream (main repo): A---B---C-----------G
\ /
fork (your GH repo): C---D---E---F
\
local (your computer): C---D---E---F
Fork the repository (via GitHub/GitLab interface)
Clone your fork:
git clone https://github.com/your-username/project.git
cd projectAdd upstream remote:
git remote add upstream https://github.com/original-owner/project.gitVerify remotes:
git remote -vCreate a feature branch:
git checkout -b feature/awesome-featureMake changes and commit:
# Make changes
git add changed-files
git commit -m "Implement awesome feature"Push to your fork:
git push -u origin feature/awesome-featureCreate pull request (via GitHub/GitLab interface)
Update your PR when requested:
# Make changes based on feedback
git add changed-files
git commit -m "Address review comments"
git push origin feature/awesome-featureKeep your fork in sync with the upstream repository:
# Fetch upstream changes
git fetch upstream
# Checkout your fork's main branch
git checkout main
# Merge upstream changes
git merge upstream/main
# Update your fork on the server
git push origin mainThe pull request process in a Forking Workflow typically involves:
- Developer pushes changes to their fork
- Developer creates PR from fork to upstream repository
- Maintainers review the code
- Developer makes requested changes on their branch
- Maintainers approve and merge the PR
- Developer syncs their fork with upstream
💡 Tip: Before creating a new PR, always sync your fork with the upstream repository to avoid conflicts.
Trunk-Based Development is a source-control practice where developers merge small, frequent updates to a core "trunk" branch (usually main). It emphasizes keeping the trunk always releasable and using feature toggles instead of feature branches.
Best suited for:
- DevOps-oriented teams with strong CI/CD practices
- Teams practicing continuous deployment
- Organizations focused on reducing integration friction
Visual representation:
main: A---B---C---D---E---F---G---H---I
↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
commits merged multiple times daily
Pull latest trunk:
git checkout main
git pull origin mainCreate short-lived feature branch (optional):
git checkout -b small-featureMake small, incremental changes:
# Make changes
git add changed-files
git commit -m "Implement small part of feature"Integrate frequently (at least once daily):
git checkout main
git pull origin main
git merge small-feature
git push origin main
# If using feature branch
git branch -d small-featureInstead of long-lived branches, Trunk-Based Development uses feature toggles:
// Example feature toggle in code
if (FeatureFlags.isEnabled("new-billing-system")) {
// New implementation
return newBillingSystem.calculateTotal(items);
} else {
// Old implementation
return oldBillingSystem.calculateTotal(items);
}Types of feature toggles:
- Release toggles (enable/disable functionality)
- Experiment toggles (A/B testing)
- Ops toggles (control operational aspects)
- Permission toggles (user-specific features)
Trunk-Based Development relies heavily on automated testing:
- Every commit triggers a CI build
- Automated test suite runs on each build
- Build breaks are fixed immediately (highest priority)
- Passing builds can be auto-deployed to staging environments
| Aspect | Trunk-Based Development | Feature Branches |
|---|---|---|
| Integration Frequency | Continuous (multiple times daily) | At feature completion |
| Branch Lifetime | Hours to a day | Days to weeks |
| Merge Conflicts | Minimal due to frequent merges | Can be significant |
| Code Review | Often post-merge, or pair programming | Pre-merge via PRs |
| Feature Isolation | Via feature toggles in code | Via branches |
| Release Cadence | Continuous | Batch |
| CI/CD Integration | Essential | Helpful but not required |
GitHub Flow is a lightweight, branch-based workflow built around core GitHub features. It's simpler than Gitflow, focusing on frequent deployment and rapid feedback.
Best suited for:
- Web applications with continuous deployment
- Teams using GitHub exclusively
- Projects with simple release requirements
- Teams wanting minimal process overhead
Visual representation:
main: A---B---C---D------F---G
\ /
feature: E---/
Create a branch:
git checkout main
git pull origin main
git checkout -b descriptive-branch-nameAdd commits:
# Make changes
git add changed-files
git commit -m "Clear description of changes"
# Continue making changes
git add more-files
git commit -m "More changes"Open a Pull Request:
git push -u origin descriptive-branch-nameThen create PR via GitHub interface
-
Discuss and review:
- Team members review code and provide feedback
- CI runs tests automatically
- Make additional commits to address feedback
-
Deploy and test:
- Deploy branch to staging/test environment
- Verify functionality in a production-like environment
-
Merge to main:
- Use GitHub's "Merge Pull Request" button
- Delete the branch after merging
GitHub Flow assumes continuous deployment:
- Merged changes to
maintrigger automatic deployment - Deployments can be to staging first, then production
- Any issues found are fixed in a new branch
- Focus on quick fixes rather than reverting
| Feature | GitHub Flow | GitFlow |
|---|---|---|
| Complexity | Simple | Complex |
| Branches | One primary (main) + feature branches | Multiple permanent branches + feature/release/hotfix branches |
| Release Cycle | Continuous | Scheduled |
| Ideal For | Web apps, continuous deployment | Versioned software |
| Production Branch | main |
main and release branches |
| Integration | Feature branches merge directly to main | Feature branches merge to develop |
| Multiple Versions | Not supported | Supported |
| Learning Curve | Low | Moderate |
GitLab Flow combines feature-driven development with issue tracking. It extends GitHub Flow with environment branches and optional release branches.
Best suited for:
- Teams using GitLab or similar platforms
- Projects requiring staged deployments
- Projects that need both continuous delivery and versioned releases
Visual representation:
production: ------------A------------------B--
/ /
main: C---D---E---F---G---H---I---J---K---L
\ \
feature: M---N---------O
GitLab Flow uses environment branches as promotion stages:
feature → main → pre-production → production
For projects requiring versioned releases:
feature → main → release-1.0 → release-1.1
Create a feature branch:
git checkout main
git pull origin main
git checkout -b 123-fix-login-issueMake changes and commit:
# Make changes
git add changed-files
git commit -m "Fix login timeout issue #123"Push branch and create merge request:
git push -u origin 123-fix-login-issueThen create merge request via GitLab interface
-
Merge to main after approval:
- Use GitLab's merge button
- Main branch is automatically deployed to staging environment
-
Promote to production:
Either:
# For environment branches approach
git checkout production
git merge main
git push origin productionOr:
# For release branches approach
git checkout main
git checkout -b release-1.0
git push origin release-1.0GitLab Flow offers two release strategies:
-
Environment branches:
- Production branch represents production environment
- Changes flow from main → pre-prod → production
- Ideal for continuous deployment with verification stages
-
Release branches:
- Each release has a dedicated long-lived branch
- Only bug fixes are merged into release branches
- Ideal for software that needs multiple supported versions
| Workflow | Complexity | Branch Types | Best For | Release Cadence | Learning Curve |
|---|---|---|---|---|---|
| Centralized | Low | Single (main) | Small teams, simple projects | As needed | Very Low |
| Feature Branch | Low | Main + feature branches | Most teams | As needed | Low |
| Gitflow | High | Main, develop, feature, release, hotfix | Complex, versioned projects | Scheduled | High |
| Forking | Medium | Same as underlying workflow + fork | Open source, public projects | Varies | Medium |
| Trunk-Based | Low | Main + short-lived feature | CI/CD, DevOps teams | Continuous | Medium (technical practices) |
| GitHub Flow | Low | Main + feature branches | Web apps, continuous deployment | Continuous | Low |
| GitLab Flow | Medium | Main, environment/release + feature | Staged deployment | Continuous or scheduled | Medium |
Consider these factors when choosing a workflow:
- Team size and geographical distribution
- Release frequency and versioning requirements
- Project complexity and codebase size
- Contributor expertise and Git familiarity
- Integration with CI/CD and deployment processes
- Need for multiple supported versions
Most teams adapt standard workflows to their needs:
- Combining elements from different workflows
- Adapting branch naming and management
- Integrating with organization-specific tooling
- Evolving the workflow as team needs change
💡 Tip: Document your workflow and keep the documentation updated as your process evolves.
Effective Git workflows integrate with CI systems:
# Example GitHub Actions workflow
name: Build and Test
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up environment
run: npm install
- name: Run tests
run: npm testKey CI best practices:
- Build and test on every commit
- Run the same CI process for branches and PRs
- Keep build times fast to enable frequent integration
- Prioritize fixing broken builds
Effective code reviews depend on the workflow:
- Pre-merge reviews: Used in Feature Branch, GitHub Flow, GitLab Flow
- Post-merge reviews: Sometimes used in Trunk-Based Development
- Pair programming: Can replace formal reviews in some teams
Review best practices:
- Focus on small, focused changes
- Use automated tools for style and basic errors
- Review for design, maintainability, and correctness
- Build review into the workflow rather than as an afterthought
Different workflows approach releases differently:
- Continuous deployment: Changes in main go directly to production
- Environment promotion: Changes move through staging environments
- Release branches: Changes are batched into scheduled releases
- Tags and versions: Specific commits are tagged for release
Release notes automation:
# Generate changelog from commits
git log --pretty=format:"%h - %s (%an)" v1.0.0..v1.1.0 > CHANGELOG.mdDocument your Git workflow:
- Branch naming conventions and purposes
- Commit message format and expectations
- PR/MR templates and requirements
- Release procedures and checklists
- Responsibility matrix for merge approvals
- Handling of critical fixes
Example PR template:
## Description
[Description of the changes]
## Issue
Closes #123
## Type of change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Checklist
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] CI tests passing| Operation | Command | Description |
|---|---|---|
| Create Feature Branch | git checkout -b feature/name |
Start new feature |
| Push New Branch | git push -u origin feature/name |
Push branch to remote |
| Track Upstream | git remote add upstream <url> |
Add original repo as upstream |
| Sync with Upstream | git fetch upstream && git merge upstream/main |
Update fork from original |
| Start GitFlow Feature | git flow feature start <name> |
Begin new feature using GitFlow |
| Finish GitFlow Feature | git flow feature finish <name> |
Complete feature using GitFlow |
| Start Release | git flow release start <version> |
Begin new release using GitFlow |
| Finish Release | git flow release finish <version> |
Complete release using GitFlow |
| Create Hotfix | git flow hotfix start <version> |
Begin new hotfix using GitFlow |
- Creating, managing, and navigating branches
- Combining branches with merge and rebase operations
- Working with remote repositories
- Advanced Git techniques and features
- Automating tasks with GitHub Actions