GitHub Flow, Forks and Issues
Follow the GitHub flow that many teams use daily, contribute to projects you cannot push to with forks, and track work with issues.
Welcome back!
Step 1 of 14Learn
One simple rule: main is always deployable
Teams need an agreement about how work moves from an idea to production. Without one, people push half-finished work to main, deploys break, and nobody knows what's live.
The GitHub flow is a lightweight agreement used by many teams, from two-person startups to large companies. It rests on one rule: anything in main is deployable. Everything else follows from that:
- Create a branch from
mainwith a descriptive name. - Make commits on that branch.
- Open a pull request early, even as a draft, to start the discussion.
- Discuss and review; push more commits in response.
- Automated checks run on the PR.
- Merge into
mainonce it's approved and the checks pass. - Deploy, often automatically, right after the merge.
- Delete the branch.
There are heavier models, such as Git Flow with separate develop, release and hotfix branches, which suit products with scheduled versioned releases. For websites, apps and most internal tools that deploy continuously, GitHub flow is simpler and enough. Whatever your team uses, the shape is the same: short-lived branches, review before merging, and a protected main line.
Step 2 of 14Learn
Keeping your branch up to date
Short-lived branches stay close to main, but even a two-day branch can fall behind while teammates merge their own PRs. Before you open a PR, and whenever it's been a while, bring the latest main into your branch:
git switch main
git pull
git switch fix-date-format
git merge main
Conflicts, if any, appear now on your branch, where you can fix them calmly, instead of blocking the PR. (Teams that prefer linear history use git rebase main instead, which is fine as long as nobody else is working on your branch.) GitHub's PR page also shows an Update branch button when your branch is behind.
The pull-merge-push rhythm becomes second nature:
- Start the day with
git switch mainandgit pull. - Branch for each piece of work.
- Commit in small steps; push at least daily so your work is backed up and visible.
- Merge
maininto your branch regularly. - Open the PR as soon as there's something to discuss.
The longer a branch lives apart from main, the more painful the eventual merge. Most "Git is hard" stories are really stories about a branch that lived for six weeks.
Step 3 of 14Diagram
GitHub flow
Tap a shape with to see more.
- Issue
Describe the bug or feature.
- Branch from main
Short, descriptive name.
- Commit and push
Small steps, pushed often.
- Pull request
Discussion, review, checks.
- Merge and deploy
Main stays deployable.
Step 4 of 14Practice · Put in order
Put the GitHub flow in order.
Drag the items, or use the arrow buttons, to put them in order.
- Delete the branch
- Commit changes on the branch
- Open a pull request
- Merge into main and deploy
- Review, discuss and pass automated checks
- Create a descriptive branch from main
Step 5 of 14Learn
Forks: contributing without write access
Suppose you find a typo in the documentation of an open-source library you use. You can clone it, but you can't push a branch, because only maintainers have write access. The answer is a fork: your own copy of the repository on GitHub, under your account.
- Click Fork on the project's GitHub page. GitHub creates
you/library. - Clone your fork:
git clone https://github.com/you/library.git. - Create a branch, commit the fix, and push to your fork (
origin). - On GitHub, open a pull request from your fork's branch to the original project's
main. The maintainers review it like any other PR.
To keep your fork current while the original moves on, add the original as a second remote, conventionally named upstream:
git remote add upstream https://github.com/owner/library.git
git fetch upstream
git merge upstream/main
GitHub also offers a Sync fork button on your fork's page that does the same thing.
Inside a company, people with write access usually skip forks and push branches to the shared repository directly. Forks are mainly for open source and for any project where you aren't a collaborator.
Step 6 of 14Practice · Diagram
Contributing through a fork
At which step do you need write access you actually have?
Tap the shape that answers the question, then press Check.
- Upstream repo
The original project you can't push to.
- Fork on GitHub
Your own copy under your account.
- Clone your fork
Work locally on a branch.
- Push to your fork
You have write access there.
- PR to upstream
Maintainers review and merge.
Step 7 of 14Practice · Sort into groups
Would you typically use a fork or a branch in the shared repository?
Tap an item, then tap its group (or drag it there).
Step 8 of 14Learn
Issues: where work begins
Most changes start as an issue, GitHub's built-in tracker for bugs, feature requests, questions and tasks. Each issue gets a number, such as #57, a title, a description and a discussion thread.
A good bug report saves everyone time. It includes what you did, what you expected, what happened instead, steps to reproduce it, and relevant details like browser, version or error message. "Checkout broken" gets a reply asking for details; "Clicking Pay with an empty cart shows a blank page in Firefox 133; expected an empty-cart message; steps below" gets fixed.
Issues can be organized with labels (bug, enhancement, good first issue), assignees, milestones for a release, and Projects boards that show work in columns such as To do, In progress and Done.
Issues and PRs link together. Mention #57 anywhere and GitHub creates a link. Write a closing keyword in a PR description, such as Closes #57, Fixes #57 or Resolves #57, and the issue closes automatically when that PR is merged into the default branch. Mention a person with @username to notify them.
For open-ended conversation that isn't a task, many projects enable Discussions, which keeps the issue list focused on actionable work.
Step 9 of 14Practice · Fill in the blanks
Fill in the blanks
A PR description that should automatically close issue 57 when the PR is merged can include the line ` #57`.
Step 10 of 14Learn
Protecting main
The rule "main is always deployable" is easier to keep when GitHub enforces it. Repository admins can add branch protection rules (or the newer rulesets) to main:
- Require a pull request before merging, so nobody pushes directly.
- Require approvals, for example at least one review from someone other than the author.
- Require status checks to pass, so the PR can't merge while tests fail.
- Block force pushes and deletion of the branch.
- Require branches to be up to date with main before merging.
A CODEOWNERS file can name the people or teams responsible for parts of the codebase, such as /billing/ @finance-devs, so they're automatically requested as reviewers for PRs touching those files.
Access itself is managed through repository roles. On a personal repository you invite collaborators; in an organization, teams get roles like read, triage, write, maintain and admin. Give people the least access they need: most contributors need write, very few need admin.
These rules aren't about distrust. They protect everyone from the Friday-night mistake, including the most senior developer on the team.
Step 11 of 14Flashcards
Branch protection, one rule per card
Tap a card to flip it.
Step 12 of 14Practice · True or false
With branch protection requiring pull requests on main, even a repository admin can be prevented from pushing directly to main.
Step 13 of 14Practice · Choose one
You want to fix a bug in an open-source project where you have no write access. What is the correct sequence?
Step 14 of 14Practice · Select all that apply
Which of these does the GitHub flow recommend? Select all that apply.
Select all that apply.
Lesson complete!