Sub topic 3
Fork the repository
This chapter covers the first step of the workflow: creating your own copy of a project on GitHub. It assumes you have a GitHub account, a configured Git installation, and basic comfort with the terminal. You have also picked a project and read its contribution guidelines.
What a fork gives you
A fork is a new repository on GitHub, under your account, that starts as a copy of another repository. You don't have write access to the original, which this tutorial calls upstream. You do have full write access to your fork, so you can push branches there and then ask the upstream maintainers to pull your changes in.
A fork exists only on GitHub. It is not on your computer yet. You make a local copy in the next chapter.
Create the fork
- Open the upstream repository's page, for example
https://github.com/ORIGINAL-OWNER/REPO. - Click Fork near the top right.
- On the "Create a new fork" page, choose the Owner. This is normally your personal account. If you belong to an organization, it appears in the list too.
- Keep the Repository name unless it clashes with a repository you already have.
- Decide on Copy the default branch only. It is checked by default. Leave it checked for most contributions, because you will create your own branches anyway.
- Click Create fork.
GitHub sends you to https://github.com/YOUR-USERNAME/REPO. Under the repository name you will see "forked from ORIGINAL-OWNER/REPO". That line confirms you are looking at your copy and not the original.
What is and isn't copied
| Copied | Not copied |
|---|---|
| Files and full commit history | Issues and pull requests |
| The default branch (all branches if you unchecked the option) | Stars and watchers |
| The license and the README | Repository secrets and settings |
Your fork is a snapshot. Once it exists, it does not update itself when upstream changes. A later chapter covers keeping it current.
Common errors
- No Fork button, or it is disabled. You may already own the repository, or the owner may have disabled forking. Private repositories and some organization repositories restrict forks. Ask the maintainers whether contributions go through another route.
- You already have a fork. GitHub points you to your existing fork instead of making a second one. Reuse it. Don't delete it just to start again unless it holds nothing you need.
- Name conflict. If your account already has a repository with that name, change the Repository name field on the creation page. Your local folder and remote URLs will then use the new name.
- Forked the wrong repository. Popular projects often have many forks, and search results can show a fork instead of the original. Check that the page does not say "forked from" before you click Fork. If it does, follow the link to the true upstream.
Exercise
You click Fork and land on a page whose header reads "YOUR-USERNAME/REPO" with the line "forked from ORIGINAL-OWNER/REPO" below it. Two days later, upstream merges a new feature. Does your fork contain it automatically, and which repository is the one you can push to?
Show answer
No. A fork is a snapshot and does not update itself, so you must sync it from upstream yourself. The repository you can push to is your fork, YOUR-USERNAME/REPO. You have no write access to ORIGINAL-OWNER/REPO.