How to create a pull-request branch

Published on


You forked a repository on GitHub, made a bunch of changes and then pushed them to GitHub. Now you want to submit a pull-request to fix a bug you found. However, because your fork is a dozen revisions beyond the original repository you’re certain your pull-request will be rejected.


Create a new branch which copies the current state of the original repository, make your change, and then submit your pull-request.


You always ought to create a separate branch for pull-requests.

Create a remote tracking branch called “upstream” which tracks the master branch of the original repository.

  $ git remote add upstream

Fetch the latest changes from the branch upstream:

  $ git fetch upstream

Create a new branch for the pull-request called pr-bug-fix and switch to that branch

  $ git checkout -b pr-bug-fix

Reset pr-bug-fix to the current state of upstream

  $ git reset --hard upstream/master --

Now pr-bug-fix is synchronized with the current state of the original repository. As such, you can safely fix the bug submit the pull-request.


Edited formatting