Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Git rebase from a forked repository

Rebase from a forked repository

Add the main repository as a remote

Remotes represent the URLs of Git repositories, e.g. origin.

Make sure you have the main repository as a remote:

$ git remote -v
origin (fetch)
origin (push)

If not, add the main repository as a new remote:

$ git remote add upstream
$ git remote -v
origin (fetch)
origin (push)
upstream (fetch)
upstream (push)

⚠️ This example works for the MeiliSearch repository: don't forget to replace MeiliSearch by the repository name on what you are working!


The goal of the rebase is to move your commits (from your branch) to be placed right after the last commit on main, keeping the Git history clear. See this documentation for more details about the rebase.

Make sure you are on main and your local commits on main are up-to-date with the upstream ones:

$ git checkout main
$ git pull upstream main

Go back to your branch and rebase:

$ git checkout your-branch-name
$ git pull origin your-branch-name # In case you accepted commit suggestions on the GitHub interface
$ git rebase main

You might have some merge conflicts. Fix them (git status could help you about what to do).

Merge conflicts or not, you finally have to do:

$ git push --force origin your-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment