GitHub Flow
GitHub flow is a simple, branch-based workflow used by many teams. It has one rule: main is always deployable. All work happens on short-lived branches that are reviewed and merged through pull requests.
The six steps
| Step | What you do | Git / GitHub |
|---|---|---|
| 1. Create a branch | name it after the work: fix/checkout-total |
git switch -c fix/checkout-total |
| 2. Make commits | small, well-described commits | git add, git commit |
| 3. Open a pull request | describe the change, link the issue | git push -u origin …, then Compare & pull request |
| 4. Discuss and review | teammates comment; automated tests run | more commits on the same branch update the PR |
| 5. Deploy (optional) | some teams deploy the branch to a test environment first | CI/CD |
| 6. Merge | merge the PR into main and delete the branch |
Merge pull request → Delete branch |
A complete round
This script plays every role: you on the left, the GitHub server as a bare repository, and a reviewer who merges on "GitHub" (a separate clone). A PR merge on GitHub creates a merge commit with a message like Merge pull request #7 from …:
git init -q --bare ~/github/shop.git
mkdir shop && cd shop && git init -q
printf 'def total(prices):\n return sum(prices)\n' > checkout.py
git add . && git commit -q -m "Add checkout total"
git remote add origin ~/github/shop.git && git push -q -u origin main
# 1-2. branch and commit
git switch -q -c fix/checkout-total
printf 'def total(prices):\n return round(sum(prices), 2)\n' > checkout.py
git commit -q -am "Round checkout total to cents"
# 3. push and open a PR
git push -q -u origin fix/checkout-total
# 4. review feedback -> one more commit on the same branch
printf '\n# total([0.1, 0.2]) == 0.3\n' >> checkout.py
git commit -q -am "Document rounding example"
git push -q
# 6. the reviewer clicks "Merge pull request" on GitHub
git clone -q ~/github/shop.git ~/github-ui && cd ~/github-ui
git merge -q --no-ff origin/fix/checkout-total -m "Merge pull request #7 from ada/fix/checkout-total"
git push -q
git push -q origin --delete fix/checkout-total
# back home: update main, delete the local branch
cd ~/shop
git switch -q main
git pull -q --prune
git branch -d fix/checkout-total
git log --oneline --graphDeleted branch fix/checkout-total (was 495fdf4).
* b155225 Merge pull request #7 from ada/fix/checkout-total
|\
| * 495fdf4 Document rounding example
| * 30907e2 Round checkout total to cents
|/
* bd62d81 Add checkout total
The graph shows the whole story: the PR's two commits on a side line and the merge commit that brought them into main.
Merge options on GitHub
GitHub offers three buttons for merging a pull request; repositories can enable any subset:
| Button | Result in main |
Local equivalent |
|---|---|---|
| Create a merge commit | all branch commits + a merge commit | git merge --no-ff |
| Squash and merge | one new commit containing the whole PR | git merge --squash + git commit |
| Rebase and merge | the branch commits re-created on top of main, no merge commit |
git rebase + fast-forward |
Here is what squash-merging the same branch looks like:
mkdir shop && cd shop && git init -q
echo "v1" > checkout.py && git add . && git commit -q -m "Add checkout"
git switch -q -c fix/rounding
echo "v2" > checkout.py && git commit -q -am "Round total"
echo "v3" > checkout.py && git commit -q -am "Fix typo in rounding"
echo "v4" > checkout.py && git commit -q -am "Address review comments"
git switch -q main
git merge --squash fix/rounding
git commit -q -m "Round checkout total to cents (#8)"
git log --oneline
cat checkout.pyUpdating bcc6038..fc47ca7
Fast-forward
Squash commit -- not updating HEAD
checkout.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
580fe28 Round checkout total to cents (#8)
bcc6038 Add checkout
v4
Three noisy commits became one tidy commit in main. Because the squash commit is new, Git doesn't see the branch's own commits as merged: delete a squash-merged branch with git branch -D fix/rounding.
Why it works
- Everyone always starts from a working
main. - Each change is reviewed before it lands.
- Small branches mean small, easy merges and quick feedback.
- Combined with continuous deployment, every merge can go live within minutes.
Test yourself
What is the central rule of GitHub flow?
- Commit directly to main
- main is always deployable; all work happens on branches merged by pull request
- Use a develop branch for integration
- Release once a month
A reviewer asks for changes on your open pull request. What do you do?
- Close the PR and open a new one
- Commit the changes on the same branch and push; the PR updates
- Push directly to main
- Create a tag
What does "Squash and merge" produce on main?
- A merge commit plus all branch commits
- A single new commit containing all the PR's changes
- Nothing until you pull
- A new branch