How to rebase the GitHub pull request

In this short tutorial, you will learn how to rebase a GitHub pull request.

For this demo, I’m using the OpenVINO repository. This method can be used when you already created PR in GitHub and it is out of sync with the master. Clone a copy of your repository and run the following command :

git remote add upstream https://github.com/openvinotoolkit/openvino.git

remote: A subcommand used to manage set of repositories tracked by your local repository.

add: Adds a new remote repository.

upstream: The name given to the new remote repository. This is a common convention, often used to refer to the original repository(OpenVINO) from which a fork was created.

Typically, the above command is used in the context of working with forks. For example, if you have forked the OpenVINO repository to your own GitHub account and cloned it to your local machine, you would use this command to keep track of the original OpenVINO repository (referred to as upstream) so you can pull in the latest changes from the original project.

Next, run the following command :

git fetch upstream

The command git fetch upstream is used in Git to fetch updates from a remote repository named upstream.

When you execute git fetch upstream, Git will:

  1. Connect to the remote repository named upstream.
  2. Download any changes (commits, branches, tags, etc.) that have been made in the upstream repository since you last fetched.
  3. Update your local repository’s remote-tracking branches for upstream, typically upstream/master, upstream/develop, etc.

Now “checkout” your feature branch onnx-fe-bitwise-not :

git checkout onnx-fe-bitwise-not

Now rebase with upstream/master :

git rebase upstream/master

When you run git rebase upstream/master, Git will:

  1. Fetch the latest changes from the upstream remote repository’s master branch (if you haven’t already).
  2. Move the base of your current branch to the tip of the upstream/master branch.
  3. Replay (reapply) your local commits on top of the upstream/master branch.

Finally, we can push the changes and update the MR.

git push origin onnx-fe-bitwise-not --force
Github branch after rebase
After rebasing the c3 and c4 commits in the feature branch moved to tip of the main branch as c3′ and c4′