Written and maintained by CASRAI Editorial Board
Last updated
Plain Git has no git fork command. A fork is a feature of a code-hosting platform such as GitHub: a copy of someone else’s repository that lives in your own account, linked back to the original. To fork, you click Fork on the repository’s page or run gh repo fork with the GitHub command-line tool, then use ordinary Git commands on the result.
This guide covers the full loop for a researcher who wants to change another team’s analysis code or tool: fork, clone, add the original as upstream, keep the fork current, and send changes back. It also settles the common git branch vs fork question using GitHub’s own wording.
What forking is used for in research
Forking is the route for contributing to a project where you do not have push access. The Pro Git book puts it this way: “If you want to contribute to an existing project to which you don’t have push access, you can ‘fork’ the project.” In research this covers fixing a bug in a published analysis package, adapting a lab’s pipeline to your data while keeping your edits under your control, or preserving a copy of a tool you depend on.
GitHub’s documentation describes forks as “repositories that start as copies of another repository, called the upstream repository.” The upstream name is shown below the name of your fork. Pro Git describes a GitHub fork as “simply the same project in your own namespace.”
If you plan to cite software you forked, see how to cite software, code and R packages. For planning how code will be maintained and shared, see writing a software management plan.
Git branch vs fork: which one do you need?
GitHub’s About forks page gives the shortest correct answer: “A branch is part of one repository. A fork is a separate repository with its own settings and collaboration space.”
Git fork vs branch
- Use a branch when you can push to the repository you are working in, for example your own lab’s repository. The work stays inside that one repository.
- Use a fork when you cannot push to the original. The fork is a separate repository under your account, where you can create branches freely.
Fork vs clone
A fork is made on the hosting platform and exists on its servers. A clone is a copy downloaded to your computer with git clone. The usual pattern uses both: fork on GitHub, then clone your fork.
Install or access
- A GitHub account, to fork on github.com.
- Git installed locally, from the official Git site (git-scm.com), for the clone, remote and merge commands below.
- Optional: the GitHub command-line tool
gh. See how to install the GitHub CLI.
If you are new to repositories, branches and pull requests, start with GitHub tutorials for beginners.
Per GitHub Docs, you can fork a public repository to your personal account or to an organization where you can create repositories. You cannot fork a private repository to an organization on GitHub Free.
Step by step: fork, clone, add upstream, send changes back
1. Fork the repository
On the web, as described in GitHub Docs (Fork a repo):
- Open the repository you want to fork.
- Click Fork at the top right of the page.
- Under Owner, choose the account that will own the fork.
- Optionally edit Repository name and Description.
- Optionally select Copy the DEFAULT branch only. If you leave it unselected, all branches are copied. You can add more branches later from the Branches page.
- Click Create fork.
From the command line, use gh repo fork REPOSITORY. The documented options include --org "octo-org" to fork into an organization, --clone=true to clone the fork, --remote=true to add a remote for the fork, and --remote-name "main-remote-repo" to name that remote.
2. Clone your fork
On your fork’s page, open Code and copy the URL, then run:
git clone https://github.com/YOUR-USERNAME/Spoon-Knife
3. Add the original as upstream
git remote -v
git remote add upstream https://github.com/ORIGINAL-OWNER/Spoon-Knife.git
git remote -v
The first command shows your fork as origin. The second adds the original repository as upstream. The third confirms both are listed.
4. Make changes on a topic branch and push to your fork
Pro Git’s workflow is to work on a topic branch, push that branch to your fork with git push origin <topic-branch>, and then open a pull request against the original project. GitHub Docs describe the same ending: you can create branches in your fork and open pull requests, asking the original owner to pull your changes.
Keep your fork in sync with upstream
A fork does not update itself. GitHub Docs (Syncing a fork) lists three ways:
- Web: open your fork, use the Sync fork dropdown, review the upstream commits, and click Update branch. If there are conflicts, GitHub prompts you to open a pull request to resolve them.
- GitHub CLI:
gh repo sync owner/cli-fork -b BRANCH-NAME. It fails on conflicts, and--forceoverwrites the destination branch. - Git: run
git fetch upstream, thengit checkout main, thengit merge upstream/main. If you have no unique local commits this is a fast-forward; otherwise you may need to resolve conflicts.
The Git route updates only your local copy. Run git push origin main to update the fork on GitHub.
Output and how to read it
git remote -v prints each remote name with its fetch and push URL. After the steps above you should see origin pointing at your account and upstream pointing at the original owner. If upstream is missing, git fetch upstream will fail. On GitHub, the fork’s page shows the upstream repository below the fork’s name.
Troubleshooting
“git: ‘fork’ is not a git command”
Git’s own command reference has no fork command, because forking happens on the hosting platform. Use the Fork button or gh repo fork.
Sync fails with conflicts
Both the web Update branch action and gh repo sync stop on conflicts. On the web, GitHub prompts a pull request to resolve them; with git merge upstream/main, resolve the conflicts locally. Use gh repo sync --force only if you intend to overwrite the destination branch.
Cannot fork a private repository into an organization
This is a documented limit on GitHub Free. Fork to a personal account instead, or see GitHub Docs for your plan.
Deleting a fork or removing access
GitHub’s About forks page notes that after a fork is deleted, its contributions can remain reachable in the repository network. For private repositories, removing a person’s access deletes their forks of it.
Ways to fork and sync: options compared
| Task | On the GitHub website | GitHub CLI | Git commands |
|---|---|---|---|
| Create the fork | Fork then Create fork | gh repo fork REPOSITORY |
No command; Git has no fork command |
| Copy to your computer | Code, copy URL | gh repo fork --clone=true |
git clone on your fork’s URL |
| Add the original as upstream | Not applicable | --remote=true adds a remote when forking |
git remote add upstream URL |
| Bring in upstream changes | Sync fork then Update branch | gh repo sync owner/fork -b BRANCH |
git fetch upstream then git merge upstream/main |
FAQ
What is a GitHub fork?
A repository that starts as a copy of another repository (the upstream), held in your own account with its own settings and collaboration space.
Is there a git fork command?
Not in Git itself. Forking is done on the hosting platform, for example with GitHub’s Fork button or gh repo fork.
What is the difference between a git branch and a fork?
A branch is part of one repository; a fork is a separate repository. See the branch vs fork section above.
Do I have to copy all branches when I fork?
No. Select Copy the DEFAULT branch only when creating the fork. You can add more branches later from the Branches page.
How do I send my changes back to the original project?
Push a topic branch to your fork with git push origin <topic-branch>, then open a pull request asking the original owner to pull your changes.
Sources
- GitHub Docs, Fork a repo, checked 2026-10-29
- GitHub Docs, Syncing a fork, checked 2026-10-29
- GitHub Docs, About forks, checked 2026-10-29
- Pro Git, Contributing to a Project, checked 2026-10-29








