Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

3. Updating your fork from original repo to keep up with their changes:

git pull upstream master
@lightkun10
Copy link

lightkun10 commented Feb 2, 2020

Thank you very much!

@Chadori
Copy link

Chadori commented Feb 13, 2020

Thanks everyone!

@sarahqiao9
Copy link

sarahqiao9 commented Feb 21, 2020

It works. Thanks!!!

@brandnewx
Copy link

brandnewx commented Feb 22, 2020

8 years on and still the most useful post on Github.

@CristinaSolana
Copy link
Author

CristinaSolana commented Feb 22, 2020

@sourabhdeshmukh
Copy link

sourabhdeshmukh commented Feb 26, 2020

Thanks it Worked for me. :)

@trillaxe
Copy link

trillaxe commented Feb 27, 2020

thank you!

@CompassTheSolution
Copy link

CompassTheSolution commented Mar 5, 2020

@RatnadeepBiswakarma
git rebase upstream master

should be:

git rebase upstream/master

And it worked great for me, thanks!

@luisriverag
Copy link

luisriverag commented Mar 25, 2020

I built a web based solution to sync the fork with the original using only GitHub APIs. It's all web, you don't need to do anything on the client
https://forkrefresh.herokuapp.com
As a plus it tells you the status off all your repos as compared to sources of the forks.

Thanks, worked really well on 289 forks I hadn't updated in a looooong time!!!

@pramodjodhani
Copy link

pramodjodhani commented May 4, 2020

Thanks a lot 👍

@RodolfoGS
Copy link

RodolfoGS commented Jul 26, 2020

Thanks!

@kxrob
Copy link

kxrob commented Aug 4, 2020

github should add a button / function for doing this frequently needed (fast-forward) re-sync from upstream without needing that triangle process via local repo + commandline. The local repos could cleanly track one remote.

If one does the sync via github pull-request + "switching the base" + normal Merge, a extra merge commit is inserted (because github internally uses merge --no-ff). Via "Rebase and merge" option of the merge button it doesn't create clean history either, rather produces an extended mess ("branch is N commits ahead + N commits behind ..." !) - probably because a 'commited by info' or so is added to the meta data of the commits.

@DahnJ
Copy link

DahnJ commented Aug 9, 2020

Thanks for this!

@ValentineDragan
Copy link

ValentineDragan commented Aug 17, 2020

The only fix that worked for me, thank you! :)

@CristinaSolana
Copy link
Author

CristinaSolana commented Aug 17, 2020

Glad you all are finding this helpful. :)

@zcmgyu
Copy link

zcmgyu commented Oct 13, 2020

Update Oct 13, 2020:

git pull upstream main

@swathi-vennela
Copy link

swathi-vennela commented Oct 26, 2020

fatal: Couldn't find remote ref master

after running
git pull upstream master

@mikemartino
Copy link

mikemartino commented Oct 28, 2020

Thank you.

@jasontwuk
Copy link

jasontwuk commented Dec 8, 2020

Thanks. This Helps me a lot. 🙂

@laoshaw
Copy link

laoshaw commented Dec 10, 2020

These comments all seem to depend on cloning the repo to your local computer and doing the fetch and merge there followed by a push. You can perform the sync to the upstream repo directly on github. Generate a pull request at the upstream repo (there is a link "compare forks") specifying your fork as the base and the upstream branch you want to merge as the head. Generate the pull request and if all goes well, you can accept your PR and you do not have to fetch both to your local site. The merge is done directly on github.

Thanks. Saved my day.

@nakul-shahdadpuri
Copy link

nakul-shahdadpuri commented Jan 29, 2021

Thanks, helped a lot.

@Praful932
Copy link

Praful932 commented Feb 3, 2021

I built a web based solution to sync the fork with the original using only GitHub APIs. It's all web, you don't need to do anything on the client
https://forkrefresh.herokuapp.com
As a plus it tells you the status off all your repos as compared to sources of the forks.

This helps! Thank you

@sami2020pro
Copy link

sami2020pro commented Feb 19, 2021

Thank you ❤️

@vivian-duong
Copy link

vivian-duong commented Mar 6, 2021

git pull is a git fetch and git merge in one step.
So the git fetch in step 2 is redundant if you're going to do a git pull anyway.

I second this. git fetch and then git pull won't break anything, but it's redundant.

@maryamrmz
Copy link

maryamrmz commented Mar 11, 2021

You can update it to:

git pull upstream main

@rebase-upstream
Copy link

rebase-upstream commented Mar 18, 2021

This post should have been the first Google result. Would have saved me some time.

@emrecoban
Copy link

emrecoban commented Mar 18, 2021

You can update it to:

git pull upstream main

thank you @maryamrmz it worked for me!

@mwaeckerlin
Copy link

mwaeckerlin commented Apr 10, 2021

How to keep a full project in sync, all the branches from the server and automated (no local checkout)?

I just want a slave mirror.

@mathieucarbou
Copy link

mathieucarbou commented Apr 29, 2021

Found an automatic and flexible solution using Github Actions that can be easily applied quickly to any fork.
See my blog post: https://blog.mathieu.photography/post/649318432483033088/automatic-fork-syncing-with-github
Or Gist: https://gist.github.com/mathieucarbou/96ab30024f0d3fb44cac970219d23efc

@liosc
Copy link

liosc commented Mar 19, 2022

Hi everyone.
I tried the commands suggested in this post. I was able to add the remote but when I try to pull for updating local I get the error "The unauthenticated git protocol on port 9418 is no longer supported.". I solved it using http// instead of git// when adding the upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment