Let’s say we have submitted a pull request to a public repository long ago. That repository’s main branch is updated often since then. Now that repository’s maintainer wanted to merge our pull request but our pull request branch is some number of commits behind their master branch. Therefore we need to update our pull request (branch) without any conflicts.
I had a similar experience.
In this article, I will explain you how to update pull request branch.
Let’s dive in!
This is how my branch was looked like before updating it. It says that my branch is 3 commits ahead of my forked master but 7 commits behind with Vonage:master (original repo’s master branch).
Let’s sync our forked master branch
Switch to our master branch.
$ git checkout master
Let’s add original repository as an upstream repository.
$ git remote add upstream [HTTPS]$ git fetch upstream
git fetch upstream fetches all of the branches from the original repository. This also downloads all of the required commits and files from the that repository.
Let’s merge upstream’s master with our forked master.
$ git merge upstream/master
Now our forked master branch is up to date with upstream’s master branch (original master branch).
Let’s log the commits to ensure our forked master is up to date with original repository’s master.