How to Set Up CI for GitHub Flow
GitHub Flow has one rule: main is always deployable, and every change arrives via a reviewed pull request.
GitHub Flow branches off main, opens a PR, runs checks, merges, and deploys. CI runs the test suite on pull_request and a deploy job on push to main. There are no release or develop branches to manage.
Steps
- Run tests on every
pull_requesttargetingmain. - Deploy from a
pushtomainonce the PR merges. - Gate the deploy job with
if: github.ref == 'refs/heads/main'. - Require the test check to pass before merge via branch protection.
Workflow
.github/workflows/ci.yml
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: ./deploy.sh productionGotchas
- Every merge to main ships, so keep the deploy step reliable and fast to roll back.
- GitHub Flow assumes one deploy target; multiple environments push you toward GitLab Flow.
Related guides
How to Set Up CI for Trunk-Based DevelopmentWire CI for trunk-based development where everyone commits to main behind short-lived branches, running the f…
How to Set Up CI for GitLab Flow With Environment BranchesUse GitLab Flow environment branches (main, staging, production) so a merge into each branch promotes the sam…
How to Deploy per Branch by Mapping Branch to EnvironmentMap each branch to a deployment environment in GitHub Actions so develop deploys to staging and main deploys…