GitHub Flow: Simple Branching for Continuous Delivery

Learn GitHub Flow: branch from main, review changes through pull requests, and connect merges to deployment policies, safeguards, and rollback plans.

published: reading time: 24 min read author: Geek Workbench updated: November 12, 2026
Quick Summary

GitHub Flow keeps branching simple: work on short-lived branches from main, review changes in pull requests, and merge approved work back. A merge does not by itself deploy to production. Teams decide when deployment runs and which checks, approvals, health gates, and rollback procedures protect it. This guide explains the branch workflow and where it fits.

GitHub Flow: Simple Branching for Continuous Delivery

GitHub Flow is a lightweight alternative to workflows with separate development and release branches. The central pattern is to branch from main, make a focused change, and return it through a pull request.

GitHub Flow does not define when code reaches production. A team may deploy after each merge, use a separate release step, or require environment approval and health checks first. GitHub documents merge-triggered deployments and environment gates; teams configure the trigger and safeguards in their workflows. GitHub’s deployment guidance explains the options. For rollout and recovery patterns, see Deployment Strategies.

Introduction

This guide walks through the branch and pull-request cycle, the checks that can protect main, and the deployment policy teams can attach to merged changes. It also covers rollback planning and situations where another branching model may fit better.

When to Use / When Not to Use

Use GitHub Flow When

  • Continuous deployment — You deploy to production multiple times per day or week
  • Web applications and SaaS — No packaging, signing, or app store approval process
  • Small to medium teams — Where communication overhead of complex branching outweighs benefits
  • Feature flag culture — You control feature rollout with flags, not branch timing
  • Automated testing — Your CI pipeline catches regressions before they reach main

Do Not Use GitHub Flow When

  • Scheduled releases — You ship on a calendar cadence with QA gates
  • Multiple supported versions — You need to patch v1.x while developing v2.x
  • Regulated environments — You need formal change management and release documentation
  • No CI/CD pipeline — Without automated validation, defects can reach main before anyone catches them
  • Mobile or desktop apps — Where each release requires a build and distribution process

Core Concepts

GitHub Flow has exactly three concepts:

Concept Description
main branch The shared branch kept ready for integration and release.
Feature branches Branch from main, merge back to main via pull request
Pull requests Code review, discussion, and CI validation before merge

That’s it. No release branches. No develop branch. No version branches. The simplicity is the entire point.


graph LR
    A[main - Kept Deployable] --> B[feature/new-ui]
    A --> C[feature/api-v2]
    A --> D[feature/bugfix]
    B -->|PR + CI| A
    C -->|PR + CI| A
    D -->|PR + CI| A
    A --> E[Deployment workflow, if configured] --> F[Production]

Architecture and Flow Diagram

The branch and review lifecycle, followed by an optional deployment workflow:


graph TD
    A[main - Protected branch] -->|create branch| B[feature/branch]
    B -->|commit| B
    B -->|push| C[Remote Feature Branch]
    C -->|open PR| D[Pull Request]
    D -->|code review| E[Review Feedback]
    E -->|update| C
    D -->|CI passes| F[Approved]
    F -->|merge| A
    A -->|deployment policy, if configured| G[Production]

Step-by-Step Guide

1. Create a Feature Branch

Always branch from the latest main:


# Ensure you have the latest main
git checkout main
git pull origin main

# Create and switch to your feature branch
git checkout -b feature/add-user-profile

Branch naming conventions matter for traceability:


# Good: descriptive with ticket reference
feature/PROJ-123-add-user-profile
feature/add-dark-mode
bugfix/fix-login-timeout

# Bad: vague or personal
feature/work-in-progress
johns-branch
temp-fix

2. Commit and Push Frequently

Small, focused commits make code review easier and bisect more effective:


# Make changes
git add src/components/UserProfile.tsx
git commit -m "feat: add user profile component skeleton"

git add src/styles/profile.css
git commit -m "feat: style user profile card"

# Push to remote
git push -u origin feature/add-user-profile

3. Open a Pull Request

The pull request is the heart of GitHub Flow. It’s where code review, automated testing, and team discussion converge:


# Using GitHub CLI
gh pr create \
  --base main \
  --head feature/add-user-profile \
  --title "feat: add user profile page" \
  --body "## Summary
Adds user profile page with avatar, bio, and settings link.

## Testing

- Manual: /profile endpoint renders correctly
- Unit: UserProfile component tests pass
- E2E: Profile navigation flow verified

## Screenshots

[Attach screenshots if UI changes]"

4. Review and Iterate

Pull request review is one gate before a change reaches main; CI checks and deployment approvals may add others. Treat review as part of the engineering process, not a rubber stamp. The goal is to catch problems before they merge.

What reviewers actually check for:

  • Correctness — does the code do what the description says? Are edge cases handled?
  • Test coverage — are the important paths tested, not just the happy path?
  • Readability — will the next person understand this in a hurry when debugging at 2am?
  • Security and performance implications — are there obvious concerns a second pair of eyes would catch?

How to write useful review comments: be specific. “This might break” is noise. “If user is null here, the fallback won’t render because the ?? operator has lower precedence than && — add parentheses around the null coalesce” gives the author something to act on. Use prefixes to triage feedback: nit: for minor style issues, question: for things you’re unsure about, and blocking: for issues that must be resolved before merge.

Handling disagreements: if the author disagrees with your comment, discuss it in the PR, not over Slack or email. The comment thread is the record of why something was decided a certain way. When you reach an impasse, bring in a third reviewer to break the tie. Do not merge with unresolved blocking comments.

The author’s job during review: push new commits to address feedback instead of force-pushing and hiding the history of what changed. If a comment is unclear, ask for clarification in the thread before assuming and implementing the wrong fix. Respond to every comment, even if it’s just “done” or “fixed in latest push,” so reviewers know the thread was read.

When to request a re-review: if your change addresses all blocking comments, explicitly request re-review from each reviewer. Do not assume a reviewer is watching the PR closely enough to notice updates.

The PR updates automatically with each push, but explicit re-review requests are the signal that says “this is ready for another look.”

5. Merge and Deploy

Once the required reviews and checks pass, merge the pull request. A merge updates main; it does not, by itself, deploy to production. The team configures what happens next: a deployment workflow may run automatically, wait for an environment approval, or require a separate release step. GitHub documents these options in its deployment guidance.

The command merges the pull request; a deployment follows only if the repository has a workflow configured for that event.


# Merge via CLI or UI
gh pr merge feature/add-user-profile --squash --delete-branch

Most teams use squash merges to keep main history clean, but some prefer merge commits for topology preservation.

Production Failure Scenarios

Scenario What Happens Mitigation
Bad merge reaches production A bug slips through review and CI Feature flags allow instant rollback without code changes; revert the merge commit
CI is green but production breaks Tests don’t cover the failure mode Use a staged rollout where practical, monitor production, and keep a tested rollback path
Conflicting PRs Two PRs modify the same file, only one can merge first Communicate in PR comments; rebase the second PR on updated main before merging
Long-running feature branch Branch diverges from main, merge conflicts pile up Rebase on main daily; break large features into smaller, mergeable chunks
Deploy pipeline failure A configured deployment starts but fails Follow the team’s recovery procedure; keep a known-good artifact available and test rollback before relying on it

Deployment Verification Checklist

When a merge starts a deployment under your team’s policy, verify the rollout before treating it as complete:

  • CI pipeline completed with all green checks
  • Deployment logs show successful rollout with correct commit SHA
  • Health endpoint responds with 200 OK
  • Error rate in monitoring is within normal baseline (< 1% increase)
  • Key user journeys pass smoke tests (login, core feature, checkout)
  • No new Sentry/alerting errors in the last 5 minutes
  • Database migrations (if any) completed successfully
  • Feature flags for the new feature are in the intended state
  • Rollback procedure is documented and tested if this is a high-risk deploy

Trade-off Analysis

Aspect Advantage Disadvantage
Simplicity One permanent branch, easy to understand No structure for complex release management
Speed Small changes can move from merge to release quickly Automatic deployment needs strong testing and safeguards
Code review Every change gets reviewed before merge Can become a bottleneck for large teams
History Clean linear history with squash merges Loses feature branch topology information
Risk Small changes can limit the impact of a release Frequent production releases still need monitoring and a rollback plan
Learning curve New developers can start contributing immediately Requires discipline around CI and feature flags

Implementation Snippets

Branch Protection Rules

Branch protection rules are the gatekeepers of your main branch. Without them, direct pushes bypass code review entirely, defeating the point of GitHub Flow. Configure these in your repository settings under “Branches” — or manage them as code using Terraform, CloudFormation, or the GitHub API.

The essential settings:

  • Required pull request reviews — At least one reviewer must approve before a PR can merge. For sensitive repos, require two. Dismiss stale reviews so outdated approvals don’t block legitimate re-reviews.
  • Required status checks — CI must pass before merge. Set “Require branches to be up to date” to prevent merging code that hasn’t been tested against the latest main.
  • Include administrators — Yes, even you. Branch protection only works if it applies to everyone.
  • Restrict pushes that create matching branches — Prevents someone from pushing a branch with the same name as a protected branch and then force-pushing over it.

A misconfigured setup I have seen more than once: admin override enabled, so engineers with admin access could push directly to main “in emergencies.” Within a month, main was broken and nobody knew who did it or when. The rule is simple — if main can be bypassed, it is not protected.

GitHub Actions — CI and an Automatic Deployment Example

This example runs tests on pull requests and pushes to main, then deploys from main after tests pass. That automatic deployment is a team policy implemented in the workflow, not a requirement of GitHub Flow. Add GitHub environment reviewers, wait timers, or branch restrictions if the release needs approval or additional safeguards.

# .github/workflows/ci.yml
name: CI
on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npm run lint
      - run: npm run typecheck
      - run: npm test -- --coverage

  deploy:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to production
        run: ./scripts/deploy.sh
        env:
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}

Feature Flag Integration


// src/features/userProfile.ts
import { isFeatureEnabled } from '@/utils/featureFlags';

export function UserProfilePage() {
  if (!isFeatureEnabled('user-profile')) {
    return null; // Or redirect to a fallback
  }

  return <UserProfile />;
}

// Feature flag evaluation
// src/utils/featureFlags.ts
export function isFeatureEnabled(flag: string): boolean {
  const flags = process.env.FEATURE_FLAGS || '{}';
  return JSON.parse(flags)[flag] === true;
}

Quick Revert Script


#!/bin/bash
# scripts/revert-last-merge.sh
# Revert the last merge commit on main

git checkout main
git pull origin main

# Find the last merge commit
LAST_MERGE=$(git log --oneline --merges -1 --format="%H")

if [ -z "$LAST_MERGE" ]; then
  echo "No merge commits found on main"
  exit 1
fi

echo "Reverting merge: $LAST_MERGE"
git revert -m 1 "$LAST_MERGE"
git push origin main

echo "Revert pushed. A configured deployment workflow may deploy this commit."

Observability Checklist

  • Logs: Log every PR merge event with author, PR number, and commit SHA
  • Metrics: Track PR cycle time (open to merge), deployment frequency, and mean time to recovery
  • Traces: Correlate each deployment with the PR that triggered it and any subsequent incidents
  • Alerts: Alert on deployment failure rate > 5%, PRs open longer than 3 days, or main branch CI failures
  • Dashboards: Display deployment frequency, lead time for changes, change failure rate, and MTTR (DORA metrics)

GitHub Flow vs Trunk-Based Development

GitHub Flow and trunk-based development are close relatives — same core idea, different tolerances for how long branches can live. GitHub Flow works with branches that stick around for days or weeks. Trunk-based development expects branches to be opened and closed within hours, with feature flags hiding incomplete work.

The practical difference comes down to infrastructure. GitHub Flow tolerates longer-lived branches because most teams don’t have the feature flag systems needed to merge incomplete code continuously. Trunk-based development requires that infrastructure as a baseline.

If you’re moving from GitHub Flow to trunk-based, you need:

  • Feature flag system (LaunchDarkly, Unleash, Flagsmith, etc.)
  • Canary deployment support in CI/CD
  • A culture of merging incomplete features behind flags
  • Rollback procedures that don’t require new deployments

Security and Compliance Notes

  • Branch protection: Required reviews and status checks prevent unauthorized merges to main
  • Signed commits: Require GPG-signed commits for cryptographic authorship verification
  • CODEOWNERS: Use CODEOWNERS file to require specific team reviews for sensitive directories
  • Secrets scanning: Enable GitHub secret scanning to prevent credential leaks in PRs
  • Audit log: GitHub’s audit log tracks all repository events including branch protection changes
  • Compliance gap: GitHub Flow lacks formal release artifacts — supplement with deployment logs and change tickets if required by your compliance framework

Common Pitfalls / Anti-Patterns

  1. The Staging Branch — A staging branch adds a release step to the workflow. That can be a valid team policy, but document how changes move from staging to production and what each environment verifies.
  2. Skipping Code Review — Merging your own PRs without review defeats the only quality gate. Enforce branch protection rules.
  3. Massive PRs — Pull requests with 50+ files are impossible to review effectively. Break features into smaller, reviewable chunks.
  4. Ignoring CI Failures — Allowing merges with failing checks means main is not always deployable. Make CI mandatory.
  5. No Feature Flags — If merges deploy automatically, new behavior may reach users as soon as the code ships. Feature flags can separate deployment from user release.
  6. Long-Lived Branches — Feature branches that exist for weeks defeat the purpose. Merge small, merge often.
  7. Direct Commits to main — Bypassing PRs for “emergency fixes” creates inconsistency. Use the same process for everything.

Quick Recap Checklist

  • main stays in a deployable state; document which commit or artifact is in production
  • Every change starts as a feature branch from main
  • Pull requests require at least one review before merge
  • CI pipeline runs tests, linting, and type checks on every PR
  • Document whether merges deploy automatically or require a separate release step
  • Branch protection rules prevent direct pushes to main
  • Feature flags control feature visibility independent of deployment
  • PRs are kept small and focused for effective code review
  • Define and test the rollback procedure for failed deployments
  • DORA metrics are tracked and reviewed regularly

Interview Questions

1. What is the key difference between GitHub Flow and Git Flow?

GitHub Flow has one permanent branch (main), while Git Flow has two (main and develop) plus temporary release and hotfix branches. GitHub Flow expects main to stay in a deployable state, but it does not require every merge to ship. Git Flow is often used for scheduled releases that need a stabilization period on a release branch.

In practice, GitHub Flow is simpler and faster but requires stronger automated testing and feature flag infrastructure to manage risk.

2. How do you handle a production bug in GitHub Flow?

Create a hotfix branch from main, fix the bug, open a PR, get it reviewed and merged — the same process as any other change. The speed comes from the small scope of the fix, not from bypassing the process.

If the fix needs to go out immediately, use a feature flag to disable the broken feature while the fix goes through the normal pipeline. This is faster than waiting for a merge and deployment cycle.

3. Why are feature flags important in GitHub Flow?

Feature flags decouple deployment from release. You can merge code to main and deploy it to production without exposing the feature to users. This allows you to deploy frequently while controlling when features become visible.

They also enable progressive rollout — enabling a feature for 10% of users, then 50%, then 100% — and instant rollback by toggling the flag off without deploying new code.

4. What happens when two feature branches modify the same file in GitHub Flow?

The first PR to merge wins. The second PR gets merge conflicts that need resolving before it can go in.

Fix it by rebasing the second PR on the latest main, resolving conflicts locally, then pushing. CI reruns on the rebased branch. If the conflict is messy, talk to whoever has the first PR — sometimes coordinate to let one merge first.

Prevent this by using CODEOWNERS for contested directories, announcing big changes in team channels, and splitting features into smaller PRs that touch different files.

5. How does GitHub Flow handle long-running feature branches?

It doesn't — not well, anyway. Branches older than a week or two start collecting merge conflicts and drifting from main. This is an anti-pattern.

What helps:

  • Break large features into smaller chunks behind feature flags
  • Rebase on main every day
  • Use stacked PRs — split a feature into dependent PRs that merge one after another
  • Set team norms around branch age and flag stale branches after a few days
6. What is the minimum CI/CD setup for GitHub Flow to work safely?

A GitHub Flow CI pipeline needs:

  • Automated tests — unit, integration, or E2E that run on every PR
  • Linting and type checking — catch syntax errors and type mismatches before merge
  • Build verification — code compiles and packages correctly
  • Required status checks — configured on the main branch so PRs can't bypass them

Without automated checks, a pull request can merge with regressions that review did not catch. Add the checks your project needs, or use a release process with time for additional verification.

7. How do you rollback a bad deployment in GitHub Flow?

Three options, in order of preference:

  • Feature flag rollback — Toggle off the flag for the broken feature. Instant. No redeployment. Requires feature flag infrastructure to be in place first.
  • Revert the merge commit — Run git revert -m 1 <merge-commit> and push through the normal review and deployment policy. This creates a new commit; whether it deploys automatically depends on the configured workflow.
  • Point-in-time restore — Pull a known-good container image from your registry. Last resort since it may undo several unrelated changes at once.

Whatever approach you use, document it and test it before you need it.

8. What is the difference between squash merge and merge commit in GitHub Flow?

Squash merge: All the commits in your PR collapse into one commit on main. The PR title becomes the commit message. Clean, linear history — easy to read and bisect.

Merge commit: Every commit from your feature branch gets preserved as a separate commit on main. Messier log, but you can see the full history of how the feature developed.

Rebase and merge: Your feature branch commits replay on top of main. Clean history too, but you lose the PR as an atomic unit.

Most teams use squash merge. Pick one and enforce it in repository settings.

9. When would you add a staging environment to GitHub Flow?

GitHub Flow does not require a staging branch. A team may still use one as a release gate; the important part is to define how the tested change moves to production and what the gate checks.

A separate staging step can make sense for:

  • Regulatory compliance — Change management requirements that mandate a pre-production approval step
  • Manual QA gates — Testing that genuinely cannot be automated, like accessibility audits or penetration tests
  • Blue-green setups — Where "staging" is actually your green environment and both are production-equivalent

If staging mostly duplicates production without adding a useful check, it adds upkeep without much confidence. Consider whether automated tests, environment approvals, or a staged rollout fit the release policy better.

10. How does GitHub Flow support zero-downtime deployments?

Several mechanisms work together:

  • Feature flags — Deploy new code but hide the feature until you're ready
  • Blue-green deployments — Route a small percentage of traffic to the new version (canary) before switching over fully
  • Rolling updates — Kubernetes-style restarts with health checks between batches
  • Backward-compatible migrations — Add columns, never remove them; the old code keeps working while the new code deploys

GitHub Flow alone cannot guarantee zero downtime. Keep main deployable, then use deployment safeguards such as health checks and backward-compatible migrations. If a migration needs downtime, plan and communicate that window.

11. What team structure works best with GitHub Flow?

GitHub Flow fits best with:

  • Small to medium teams — 5 to 20 developers; communication overhead stays manageable
  • Cross-functional teams — Each team can take something from design to deployment without handoffs
  • Flat hierarchies — No approval layers between developer and production merge
  • Strong code review culture — PR reviews are the only quality gate, so they actually have to happen

Once you get above 30 developers, code review turns into a bottleneck. You can work around it with CODEOWNERS and specialized review teams, or just move to trunk-based development with feature flags.

12. What is the purpose of CODEOWNERS file in GitHub Flow, and how do you set it up?

The CODEOWNERS file defines who owns specific directories or file patterns in the repository. When a PR modifies those files, the designated owners are automatically requested for review. This ensures domain experts always review changes to their areas.

Example CODEOWNERS:

# Teams
/src/api/ @api-team
/src/ui/ @frontend-team
/docs/ @docs-team

Individuals

*.sql @senior-dba /security/** @security-team

Place the file at .github/CODEOWNERS in the repository root.

13. How do you handle stale branches in GitHub Flow?

Stale branches (older than 1-2 weeks) indicate work that isn't progressing. Handle them by: setting up branch protection rules to alert on old branches, using automation to close branches with no activity for X days after notification, deleting merged branches automatically via settings or scripts, and encouraging developers to push to remote daily so branches stay current with main.

14. What happens when main is broken and needs immediate fix in GitHub Flow?

The key principle: main should never be broken. If it happens despite best practices: immediately disable the broken feature via feature flag (if infrastructure exists), revert the merge commit with git revert -m 1 <sha>, investigate why CI didn't catch the issue, fix the root cause, test thoroughly, and merge a proper fix. Never commit directly to main to "fix it fast" — this bypasses CI and can make things worse.

15. How does GitHub Flow integrate with GitHub Actions for CI/CD?

A workflow can run tests, linting, and build verification for pull requests and pushes to main. Teams that choose automatic deployment can add a production job after those checks pass; environment approvals and branch protections can add release gates. GitHub Actions follows the workflow configuration, so a push does not deploy unless the workflow says it should.

16. What is the difference between GitHub Flow and trunk-based development at scale?

GitHub Flow allows feature branches to live for days or weeks; trunk-based development restricts them to hours. At scale (50+ developers), GitHub Flow's longer branch lifetimes cause merge conflict accumulation and integration pain. Trunk-based development requires feature flag infrastructure and very fast CI, but eliminates integration debt entirely. The transition requires cultural changes: developers must be comfortable merging incomplete features behind flags.

17. How do you manage environment-specific configurations in GitHub Flow?

Environment configs should be injected at runtime, not stored in code. Use: environment variables set in CI/CD platform settings, config maps/secrets in Kubernetes, or feature flag services for feature-toggled behavior. Never commit API keys or environment-specific URLs to the repository. The same commit should be deployable to any environment with the right configuration injected.

18. What security considerations are specific to GitHub Flow?

Key security measures: require branch protection with required status checks and PR reviews, enable secret scanning to prevent credential leaks, use CODEOWNERS to ensure security-relevant code is reviewed by experts, require signed commits for production branches, enable dependency review to catch vulnerable dependencies before merge, and use GitHub's audit log to track who merged what and when.

19. How do you handle rollback when feature flags are not available?

Without feature flags, rollback options are limited: revert the merge commit (creates a new commit that undoes changes), point-in-time restore from a previous container image (may lose other legitimate changes), or push a fix forward (may take longer). The best mitigation is investing in feature flag infrastructure before you need it. Short branch lifetimes also reduce rollback blast radius.

20. What happens when CI passes but production breaks — a common scenario in GitHub Flow?

Tests don't cover everything. When this happens: immediately toggle off any related feature flags, assess the blast radius (what users are affected), decide between revert or forward fix, add missing test cases to prevent recurrence, conduct blameless postmortem, and consider canary deployments that expose new code to limited users first. The goal is to catch issues before full production exposure through better testing and staged rollouts.

Further Reading

Conclusion

GitHub Flow keeps the branch model small: main, short-lived feature branches, and pull requests. Teams can pair it with automatic deployment, a separate release step, or environment approvals. Pick the policy that fits the service, then make its checks and rollback path clear to everyone making changes.

Category

Related Posts

Choosing a Git Team Workflow

Compare trunk-based development, short-lived feature branches, and release branches against your release, review, rollback, and compliance needs.

#git #version-control #branching-strategy

Git Flow: The Original Branching Strategy Explained

Master the Git Flow branching model with master, develop, feature, release, and hotfix branches. Learn when to use it, common pitfalls, and production best practices.

#git #version-control #branching-strategy

Git Release Branching and Hotfixes: Managing Versions in Production

Master release branching and hotfix strategies in Git. Learn version branches, emergency fixes, backporting, and how to manage multiple production versions safely.

#git #version-control #release-management