Skip to content

Instantly share code, notes, and snippets.

@finwe
Last active April 17, 2018 16:40
Show Gist options
  • Save finwe/a95e26197be82f753686114720d42581 to your computer and use it in GitHub Desktop.
Save finwe/a95e26197be82f753686114720d42581 to your computer and use it in GitHub Desktop.
Rebasing a GitHub fork/pull request against the upstream repository

Add an upstream repository (only once per fork)

This is the repository from which you have created the fork

git remote add upstream https://github.com/owner/repo.git

Fetch changes from the upstream remote

git fetch upstream

Switch to your PR feature branch

You always create a feature branch for your PRs, right?

git checkout feature-1

Rebase against upstream main branch.

The name of the main branch differs in project, you will most likely find it in contributing guidelines. Most of the time it will be master, but many projects use development.

git rebase upstream/master

Go through the rebase process and resolve potential conflicts. Check your commit line afterwards, it should be straight from the upstream main branch with no further branching and merge commits.

Force push your changes

As you have a dedicated branch for your PR, you needn't worry about force pushes. The PR will update itself with new rebased commits.

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