---
title: "How do I sync my fork with the original repository?"
description: "Add the original repository as an upstream remote, fetch it, then rebase or merge its main branch into yours and push. Here is how, plus the one-click options on GitHub."
url: https://www.danny.engineering/answer/git/how-do-i-sync-my-fork-with-the-original-repository
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["Git"]
---

# How do I sync my fork with the original repository?

## The short answer


Your fork does not update itself. Add the original project as a second remote, usually called `upstream`, fetch from it, bring its changes into your branch, and push to your fork.


```bash
git remote add upstream https://github.com/original-owner/project.git
git fetch upstream
git switch main
git merge --ff-only upstream/main
git push origin main
```


## Why it happens


A fork is a full copy of the repository taken at one moment. After that, it is a separate repository. New commits in the original project do not flow into your fork, and your local clone only knows about the remote you cloned from, which is your fork (`origin`).


To get the new commits, your clone needs to know where the original lives. That is all the `upstream` remote is: a second named URL. Once it is fetched, `upstream/main` is a normal remote branch you can merge or rebase onto, just like `origin/main`.


## How to fix it


### Set up the upstream remote once


Check your remotes first. You will normally see only `origin`.


```bash
git remote -v
git remote add upstream https://github.com/original-owner/project.git
git remote -v
```


If the original project's default branch is not `main`, use its name in the commands below.


### Keep main as a clean copy of upstream


The tidiest workflow is to never commit directly to `main` in your fork. Then updating it is always a fast-forward, with no merge commits or conflicts.


```bash
git fetch upstream
git switch main
git merge --ff-only upstream/main
git push origin main
```


`--ff-only` refuses to create a merge commit. If it fails, you have commits on `main` that upstream does not, which is a sign they belong on a feature branch.


### Update a feature branch with rebase


For a branch you are preparing as a pull request, rebasing onto the latest upstream keeps your commits on top and the history linear.


```bash
git fetch upstream
git switch my-feature
git rebase upstream/main
# fix any conflicts, then: git add <file> && git rebase --continue
git push --force-with-lease origin my-feature
```


Rebasing rewrites your branch's commits, so the push needs `--force-with-lease`. It refuses to overwrite the remote if someone else pushed to it since you last fetched, which plain `--force` does not check.


### Update a feature branch with merge


If other people share the branch, or the project prefers merges, merge instead. Nothing is rewritten, so a normal push works.


```bash
git fetch upstream
git switch my-feature
git merge upstream/main
git push origin my-feature
```


### Use GitHub's sync button or the gh CLI


On GitHub, the fork's page has a **Sync fork** button that updates the fork's branch from the original on the server. You still need to pull afterwards to update your local clone.


With the GitHub CLI, you can do the same from the terminal.


```bash
gh repo sync your-name/project
git pull
```


These options work best when your branch has no commits of its own. If it has diverged, use the rebase or merge approach above so you can resolve conflicts locally.


## Common pitfalls

- **Pushing to upstream by accident.** You usually cannot, but if you have write access, double-check the remote name before pushing. Some people disable it with `git remote set-url --push upstream no-push`.
- **Committing on main.** It makes every sync a merge. Keep your work on branches.
- **Using** **`--force`** **instead of** **`--force-with-lease`****.** Plain force can silently delete commits pushed by someone else.
- **Forgetting to fetch.** `upstream/main` only updates when you run `git fetch upstream`.
- **Renamed default branch.** If upstream moved from `master` to `main`, update your local branch and its tracking to match.

## Related reading

- [git-scm.com: git remote](https://git-scm.com/docs/git-remote)
- [git-scm.com: git rebase](https://git-scm.com/docs/git-rebase)
