Forks and the Contribution Flow
A fork is your own copy of someone else's repo, the starting point for contributing.
A fork is a personal copy of another user's repository under your own account. It is the standard way to contribute to projects you do not have write access to.
The typical open-source flow
- Fork the project to your account.
- Clone your fork locally.
- Create a branch and make changes.
- Push to your fork.
- Open a pull request back to the original repo.
Example
# After clicking Fork on GitHub, clone YOUR copy
git clone [email protected]:you/awesome-project.git
cd awesome-project
# Track the original project too
git remote add upstream https://github.com/original/awesome-project.git
git pull upstream mainWhen to use it
- A developer forks a popular open-source library, fixes a bug, and submits a pull request back to the original maintainer.
- A company forks a public tool to maintain a private customised version while still pulling upstream security patches.
- A student forks a course template repo to complete assignments in their own copy without affecting classmates.
More examples
Fork a repo with GitHub CLI
Forks the repo to your account and clones it locally with both origin (your fork) and upstream (original) remotes pre-configured.
gh repo fork expressjs/express --clone
cd express
git remote -v
# origin https://github.com/you/express.git
# upstream https://github.com/expressjs/express.gitSync fork with upstream changes
Pulls the latest commits from the original project into your fork's main branch to keep it up to date.
git fetch upstream
git switch main
git merge upstream/main
git push origin mainCreate a feature branch for a PR
Commits the fix to a named branch on your fork so the upstream maintainer receives a clean, targeted pull request.
git switch -c fix/memory-leak
# Make changes
git add src/connection.js
git commit -m "fix: release connection on timeout"
git push origin fix/memory-leak
Discussion