GitHub provides different workflows depending on whether you own the repository or are contributing to someone else’s project. Understanding these workflows is essential for collaborating effectively on GitHub.

GitHub flow

GitHub flow is a lightweight, branch-based workflow. The GitHub flow is useful for everyone, not just developers. The GitHub documentation has a good overview of the process and the reasons for using it. See GitHub flow.

The basic GitHub flow consists of:

  1. Create a branch from main
  2. Make changes and commit them
  3. Push the branch to GitHub
  4. Create a pull request
  5. Review and discuss changes
  6. Merge the pull request
  7. Delete the branch

Workflow for a forked repository

If you want to contribute to someone else’s project but don’t have write access to the repository, you can use a “fork and pull request” workflow. This is the standard way to contribute to open source projects.

The following image illustrates the workflow for using Git and GitHub to update files in a forked repository. The steps shown in red are a one-time action for each new repository you fork.

Forked repository GitHub workflow

StepsDescription of stepsGit command / GitHub actions
AFork the repoBrowse to the repository on GitHub and select the Fork button (top right). Open the Choose an owner dropdown and select your personal account. Select the Create fork button.
BClone the repo (once per machine)git clone https://github.com/<your-account>/<repository-name>.git
CAdd the upstream remotegit remote add upstream https://github.com/<original-owner>/<repository-name>.git

For a full discussion of forking, see Contributing to projects in the GitHub documentation.

The numbered steps (in black) are described in the table below.

StepsDescription of stepsGit command / GitHub actions
0Checkout the main branchgit checkout main
1Sync the main branchgit pull upstream main; git push origin main
2Create a new working branchgit checkout -b my-new-branch
3Create new contentUse VS Code to create or edit files
4Add changes for Git trackinggit add -A
5Commit changes to local repogit commit -m 'commit message'
6Push working branch to forkgit push origin my-new-branch
7Submit pull requestGo to the original repository’s pull request page and click the New pull request button.Base repository: original-owner/repository-name base: main <– head repository: your-account/repository-name compare: my-new-branch Fill out the pull request description and click Submit.
8PR is reviewedMake the necessary changes based on the review feedback.
9PR is mergedGo to step 10
10Cleanup unneeded branch infogit checkout main; git push origin --delete my-new-branch; git branch -D my-new-branchThe git push command deletes the branch in your fork and deletes the tracking branch from your local repo. The git branch command deletes the branch from your local repo.
11Start new changeGo to step 0

Next ⏭