GitHub flow
Overview
Every team needs agreement on how to use branches: where new work starts, how it gets reviewed and how it reaches users. This agreement is a workflow. The most widely used one is GitHub flow — simple enough to explain in a minute, and robust enough for teams of hundreds.
The rules of GitHub flow
mainis always deployable. Anything onmaincould be released at any moment. Broken code never lands there.- Every change gets its own branch from
main, with a descriptive name:fix/footer-year,feature/search. - Commit and push regularly to the branch — it backs up your work and shows progress.
- Open a pull request when you want feedback — early as a draft, or when ready for review.
- Review and test. Teammates review; CI runs the tests on the PR.
- Merge when approved and green.
- Deploy — many teams deploy automatically after every merge to
main. - Delete the branch. It’s done.
That’s the whole workflow. There’s one long-lived branch, and everything else lives for hours or days.
A cycle, command by command
git switch main && git pull # start from the latest main
git switch -c feature/search # one branch per change
# …edit, commit, repeat…
git push -u origin feature/search # publish
gh pr create --fill # open the PR
# …review, CI, more commits…
git fetch && git rebase origin/main # keep up with main if it moved
git push --force-with-lease # (only after a rebase)
gh pr merge --squash --delete-branch # merge when approved
git switch main && git pull # back to the startMaking it work well
- Small branches. A branch that lives two days has little to conflict with. One that lives two months becomes a merge nightmare.
- Update from
mainoften — rebase or mergemaininto your branch every day or two. - Automate checks. Protect
mainso PRs need passing tests and a review before merging (Protecting branches). - Hide unfinished features behind feature flags (configuration switches) so you can merge incomplete work safely, instead of keeping a branch open for weeks.
- Deploy often. Small, frequent deploys are easier to verify and roll back.
Other workflows you’ll meet
Git Flow
An older, more elaborate model, popular for software released in versions (desktop apps, libraries with long support):
mainholds only released versions, each tagged;developcollects finished features for the next release;feature/*branches come from and merge intodevelop;release/*branches stabilise a version before it’s merged intomain;hotfix/*branches patchmainurgently.
It gives tight control over releases, but it’s heavier: more long-lived branches, more merges, more chances for them to drift. Even its author now recommends something simpler for software that’s continuously delivered, like most web applications.
Trunk-based development
The opposite direction: everyone integrates into main (the “trunk”) at least once a day, through very small PRs or even direct commits with strong automated testing. Feature flags hide work in progress. It’s GitHub flow with the branch lifetime pushed to the minimum, and it’s what many high-performing teams use.
Release branches with GitHub flow
If you need to support old versions (say, security fixes for 1.x while 2.x is current), add release branches to GitHub flow: create release/1.x from the 1.0 tag, and cherry-pick fixes onto it from main (Cherry-picking).
Choosing
| Situation | Workflow |
|---|---|
| Web app or service, deployed continuously | GitHub flow or trunk-based |
| Library or app with versioned releases | GitHub flow + tags (+ release branches if you support old versions) |
| Strict, scheduled releases with long stabilisation | Git Flow |
| Solo project | GitHub flow — branches and PRs still help you review your own work |
Start simple. GitHub flow covers most projects. Add process only when you feel a real problem it solves.
Run GitHub flow end to end
Using a local bare repository as the shared server, run two complete GitHub flow cycles for two developers. Asha builds feature/search while Ben builds fix/footer. Each pushes their branch; Ben’s “pull request” is merged first (simulate the merge button with git merge --no-ff on main and a push). Asha then updates her branch from the new main by rebasing, pushes with --force-with-lease, and her change is merged. Delete both remote branches. main must end with both merge commits and the server must have only main.
git init -q --bare -b main server.git
git clone -q server.git asha 2>/dev/null && cd asha
echo "<footer>(c) 2025</footer>" > footer.html && git add . && git commit -qm "Start site" && git push -qu origin main
cd .. && git clone -q server.git ben
# 1. Asha: branch, commit, push
# 2. Ben: branch, commit, push
# 3. "Merge Ben's PR" (merge commit on main, push, delete his remote branch)
# 4. Asha: update her branch from main, force-push safely
# 5. "Merge Asha's PR" and clean upgit init -q --bare -b main server.git
git clone -q server.git asha 2>/dev/null && cd asha
echo "<footer>(c) 2025</footer>" > footer.html && git add . && git commit -qm "Start site" && git push -qu origin main
cd .. && git clone -q server.git ben
# 1. Asha: branch, commit, push
cd asha
git switch -c feature/search
echo "<input type=search>" > search.html && git add . && git commit -qm "Add search box"
git push -u origin feature/search
cd ..
# 2. Ben: branch, commit, push
cd ben
git switch -c fix/footer
echo "<footer>(c) 2026</footer>" > footer.html && git commit -qam "Update footer year"
git push -u origin fix/footer
# 3. "Merge Ben's PR" (what the merge button does), then delete the branch
git switch main && git pull -q
git merge --no-ff -m "Merge pull request #2 from fix/footer" fix/footer
git push
git push origin --delete fix/footer
cd ..
# 4. Asha: update her branch from main, force-push safely
cd asha
git fetch
git rebase origin/main
git push --force-with-lease
# 5. "Merge Asha's PR" and clean up
git switch main && git pull -q
git merge --no-ff -m "Merge pull request #1 from feature/search" feature/search
git push
git push origin --delete feature/search
git branch -d feature/search
git log --oneline --graphSummary
- GitHub flow:
mainis always deployable; every change happens on a short-lived branch merged through a pull request. - Create a branch, commit, push, open a PR, review and test, merge, deploy, delete the branch — repeat.
- Keep branches small and short-lived, and update them from
mainoften, to avoid painful merges. - Git Flow adds long-lived develop and release branches — useful for versioned software with scheduled releases.
- Trunk-based development takes GitHub flow further: tiny branches merged at least daily, with feature flags.