60

I have a Github repository that I forked from some other project several months ago. It is now several months later and the original master repo has changed. I would like to update my repo to reflect those changes. Is this possible in the Github web interface? Or do I just need to delete the repo and re-fork it?

3

3 Answers 3

48

You can try and reverse how pull requests happen.

  1. Go to your fork
  2. Issue a Pull Request

    By default this will be your fork on the right (head repo) requesting to push its commits and changes to the original repo (base repo) on the left.

  3. Click the drop down for both base repo and head repo and select each other's repos.

    You want yours listed on the left (accepting changes) while the original repository is on the right (the one with changes to push). As illustrated in this image:

    fork done over itself

  4. Send the pull request

    If your fork has not had any changes, you should be able to automatically accept the merge.

If your code somehow conflicts or is not quite clean enough, then this will not work to update via the GitHub web interface and you will need grab the code and resolve any conflicts on your machine before pushing back to your fork.

8
  • 3
    This still works but yeah it's not ideal. Its definitely just a trick. Not the proper way to do it. Dec 3, 2014 at 5:07
  • 3
    Confirmed a bad idea. This pollutes the repository in a way that Github suggest you to pull request an empty commit to the original project. See for example github.com/dthommes/RoboSpring/pull/3 - Once I contributed to it, then I synced and now Github wants me to push a "Syncing my fork" commit labeled as " Merge pull request #1 from dthommes/master … " Dec 29, 2014 at 14:33
  • 1
    I don't think this works anymore. Although it seems a bit odd there isn't a simple way to do this.
    – Toby Allen
    Mar 6, 2016 at 19:39
  • 1
    I just tried it, and it didn't immediately seem to work - when changing one of the forks it immediately opened a "Comparing changes" page. But clicking the "compare across forks" link allowed to change the other fork anyway. Perhaps you could add something to this effect to your answer. May 10, 2017 at 19:50
  • 8
    GitHub should add a "Sync Fork" button so you don"t have to create a million PRs. For now i'm using the command line to update my forks
    – Suici Doga
    May 31, 2017 at 5:16
23
+50

It's gonna be easier.

  1. Go to the Forked Repo (yours) and just click button - "New pull request".
  2. On the page that opens, there is a small link to "switching base" in the message underneath the dropdownselects. Click the link.
  3. Now it will automatically lead to your original repo. Click Create Pull Request button and write some commit message.
  4. Now it will lead to your forked repo automatically, click Merge pull request and Confirm merge to finish.
6
  • You should clarify what those green buttons are and it would be a great response.... Mar 7, 2016 at 13:36
  • This is definitely the best answer as of 4/2016.
    – dr_
    Apr 13, 2016 at 8:48
  • 9
    The problem with this method is that it adds an extra commit to your branch, so it's not really in sync with the upstream repo.
    – Mottie
    May 22, 2016 at 13:19
  • @Mottie Is there a way for us to know if our fork is behind the latest upstream version, and see a diff of the changes, without actually pulling them? Dec 11, 2016 at 5:38
  • 1
    @SujayPhadke On your main forked repo page under the branch select button will be a message "This branch is xx commits behind xxxx:master.". As for seeing the diff, there is a "compare" button in the same row as the message; or you can go to this link: https://github.com/{user}/{forkedRepoName}/compare/master...{originalRepo}:master
    – Mottie
    Dec 15, 2016 at 23:57
3

How to update a forked GitHub repo with changes from the remote upstream repository


Instructions from GitHub Help:

Configuring a Remote Fork

Syncing a Fork


Setup / Operation Instructions:

Open Git Bash (Windows) or Linux / Mac Terminal

If you have not yet cloned your repository, you must change to the working directory of your development folder and clone it to your workstation.

$ git clone https://github.com/YOUR_USERNAME/YOUR_FORK.git

Change to the working directory of your forked repo on your workstation.

$ cd /user/development/my_forked_repo/

List the current configured remote repository for your fork.

 $ git remote -v

origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

Specify a new remote upstream repository that will be synced with the fork.

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

Verify the new upstream repository you've specified for your fork.

$ git remote -v

origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master.

$ git fetch upstream

remote: Counting objects: 75, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 62 (delta 27), reused 44 (delta 9)
Unpacking objects: 100% (62/62), done.
From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
 * [new branch]      master     -> upstream/master

Check out your fork's local master branch.

$ git checkout master

Switched to branch 'master'

Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes.

$ git merge upstream/master

Updating a422352..5fdff0f
Fast-forward
README                    |    9 -------
README.md                 |    7 ++++++
 2 files changed, 7 insertions(+), 9 deletions(-)
 delete mode 100644 README
 create mode 100644 README.md

If your local branch didn't have any unique commits, Git will instead perform a "fast-forward":

$ git merge upstream/master

Updating 34e91da..16c56ad
Fast-forward
 README.md                 |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

You will now need to push the commits to your fork.

$ git push

If you are not already authenticated, it will prompt for your github username / password. Once authenticated the new commits should be pushed to your fork and visible on github.

1
  • 5
    Thank you for your detailed answer however the hope was for a solution using the web interface.
    – Toby Allen
    Mar 11, 2016 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.