12

I have forked a github project, then cloned it locally.

I then made some changes in a new branch on my_github/the_project repo.

I then added and committed the changes and pushed to my github repo and submitted a pull request.

The owner has received my request and would like me to "rebase onto master" to get the latest changes. How do I do this?

Initially I thought I could just git fetch and rebase master from within my current branch (as most posts I found advise...), but git fetch didn't do anything. Now I've realized that it is presumably because I'm still fetching from my_ github/repo clone (it's my name in the remotes after all) which hasn't yet got the new changes in master from the github source owner.

I think what I probably need to do is "refresh" my fork so that my fork's master is up-to-date and then I can fetch that master and then rebase on to that master?

If this is the case how can I do that refresh of my forks master? If not how else?

Should I add a remote for the original upstream repository and use that to rebase with (locally)? Is this the preferred method?

Michael Durrant
  • 84,444
  • 83
  • 284
  • 429

1 Answers1

12

Yes, it's not fetching anything because of the reason you surmised. And yes, you should add a remote for upstream locally; it will do a fast-forward merge on master.

git checkout master # Make sure you are in master
git remote add author original_repo_that_you_forked_from
    # Note: This is in the format git@github.com:authors_name/repo_name.git
    #       Only needs definition once, future fetches then use it. 
git fetch author
git status # make sure you are in the master branch for the following merge
git merge author/master  # i.e. 'into' your master branch
git checkout your-branch
git rebase master        # Now get those changes into your branch.
git push origin your_branch # You can also use `-f` if necessary and `--all`

(sorry, I might not have the syntax exactly right)

Robin Green
  • 29,408
  • 13
  • 94
  • 178
  • You might want to specify the remote in the push, like `git push origin --all`, but otherwise that is exactly what I'd suggest. – Leigh Nov 09 '13 at 23:15
  • From this github [rebase and merge blog](https://github.com/blog/2243-rebase-and-merge-pull-requests), can we say that even if the contributor has not rebased the change, it should be very convienient for the _author_ to rebase and merge? If this is the case, I don't understand why a PR is put on hold because it's not rebased. – Felix Jul 01 '17 at 07:15
  • 1
    Because if there are conflicts, the maintainer won't necessarily know how to fix them. The author is best placed to fix them. – Robin Green Jul 01 '17 at 09:56