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
@CristinaSolana

This comment has been minimized.

Copy link
Owner Author

commented Feb 22, 2012

I use 'master' in the example for pulling from the original repo, but you could pull from any branch.

@metude

This comment has been minimized.

Copy link

commented Nov 8, 2012

I tried this but it didn't updated my repo in github.com? So how can I send them to github.com? (I'm a bit new.)

@jjt

This comment has been minimized.

Copy link

commented Dec 12, 2012

@metude You've just updated your local repo and need to push your changes:

git push
@bertomartin

This comment has been minimized.

Copy link

commented Oct 29, 2013

What happens if the branch you wanna pull from was created after you forked the original repo? If you're on the 'master' branch of your repo, can you do: git pull upstream new-upstream-branch?

@ncrash

This comment has been minimized.

Copy link

commented May 7, 2014

Thanks!!

@vlad-light

This comment has been minimized.

Copy link

commented Oct 27, 2014

Is it still Up-To-Date? In my forked repo i see the message "This branch is 2 commits behind avalanche123:develop" so I tried to follow your instructions to get all last changes from original repo, but everytime I execute git pull upstream develop I get a message:

From https://github.com/avalanche123/Imagine
 * branch            develop    -> FETCH_HEAD
Already up-to-date.

Do I miss something ?!

@sudoer

This comment has been minimized.

Copy link

commented Feb 16, 2015

Thanks for sharing! I'm learning by doing.

@timmaybrown

This comment has been minimized.

Copy link

commented Jun 26, 2015

Thank you so much!

@mtjhax

This comment has been minimized.

Copy link

commented Jul 13, 2015

Part of official docs now: https://help.github.com/articles/syncing-a-fork/ (note that their example uses rebase instead of pull to get changes from upstream -- depends on your preference)

@SkyzohKey

This comment has been minimized.

Copy link

commented Apr 2, 2016

Thanks. Saved my day. :3

@NitroBAY

This comment has been minimized.

Copy link

commented Apr 8, 2016

Thanks

@wolf99

This comment has been minimized.

Copy link

commented May 12, 2016

Awesome, thanks!

@vis4573

This comment has been minimized.

Copy link

commented Jun 1, 2016

Thank You !

@NexusInk

This comment has been minimized.

Copy link

commented Jun 24, 2016

Git also does this via 'sync' on Desktop.

@evrpg

This comment has been minimized.

Copy link

commented Sep 10, 2016

Thank you working just fine.

@zbyna

This comment has been minimized.

Copy link

commented Sep 17, 2016

Thanks, I got it finally 😃

@andreasblueher

This comment has been minimized.

Copy link

commented Oct 12, 2016

Thank you very much! 👍

@xCyborg

This comment has been minimized.

Copy link

commented Oct 14, 2016

Can you do that from the website?

@grabcode

This comment has been minimized.

@robincher

This comment has been minimized.

Copy link

commented Dec 12, 2016

Thanks for the help! It's working right here

@mamakancha

This comment has been minimized.

Copy link

commented Dec 15, 2016

Thanks. Helped me a lot :)

@isabellerichard

This comment has been minimized.

Copy link

commented Jan 13, 2017

Top 👍

@conorbmurphy

This comment has been minimized.

Copy link

commented Jan 17, 2017

This is the clearest solution I've seen--thank you!

@AdrianAntunez

This comment has been minimized.

Copy link

commented Jan 24, 2017

Thank you so much! That detailed explanation makes the process a peace of cake

@mitchellkrogza

This comment has been minimized.

Copy link

commented Jan 28, 2017

works like a charm, thank you

@lucapierobon

This comment has been minimized.

Copy link

commented Feb 5, 2017

that's exactly what I was looking for! thanks a lot!

@MajesticFalcon

This comment has been minimized.

Copy link

commented Feb 6, 2017

Thank you

@mmccool

This comment has been minimized.

Copy link

commented Feb 14, 2017

Thanks a lot! I really wish there was a way to do this from the website, though.

@karthik972

This comment has been minimized.

Copy link

commented Mar 6, 2017

Isn't "git rebase upstream/master" is better option than "git pull upstream master" ? This will work properly even if the current branch has few commits extra than in the upstream master.

@4leem

This comment has been minimized.

Copy link

commented Mar 23, 2017

Thanks! Work like a charm

@OtacilioN

This comment has been minimized.

Copy link

commented Mar 25, 2017

Thank you so much!

@qct

This comment has been minimized.

Copy link

commented Apr 1, 2017

origin has 1 branch, but upstream has 3 branches, how to sync origin with upstream?

@pierx

This comment has been minimized.

Copy link

commented Apr 27, 2017

Thanks

@blachawk

This comment has been minimized.

Copy link

commented May 10, 2017

Thanks!

@mohamessi

This comment has been minimized.

Copy link

commented May 11, 2017

Thanks you very mutch.

@david-sackstein

This comment has been minimized.

Copy link

commented May 20, 2017

I followed the instructions in the documentation and also received this:
From https://github.com/

  • branch develop -> FETCH_HEAD
    Already up-to-date.
    My history as in git log has not changed and I have no uncommitted changes.
    Why do I not see a merge commit?
@qazqwezxc

This comment has been minimized.

Copy link

commented May 21, 2017

Awesome, worked as intended.

Thanks!

@duncombe

This comment has been minimized.

Copy link

commented Jun 5, 2017

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.

@Pradhvan

This comment has been minimized.

Copy link

commented Jun 12, 2017

Thanks !

@leamtrop

This comment has been minimized.

Copy link

commented Jun 28, 2017

Thanks!

@jfeng10

This comment has been minimized.

Copy link

commented Jul 4, 2017

Great! It saves me a lot of time. Thank you! :)

@chathuralakmal

This comment has been minimized.

Copy link

commented Jul 5, 2017

Thanks.

@jishnujayakumar

This comment has been minimized.

Copy link

commented Jul 12, 2017

Great. Helped me a lot. Thank you! :)

@azzamsa

This comment has been minimized.

Copy link

commented Jul 19, 2017

Great! It saves my day. Thank you! :)
have a nice day!.

@tuhinsharma121

This comment has been minimized.

Copy link

commented Jul 19, 2017

Works fine!! Thanks!!

@pepa65

This comment has been minimized.

Copy link

commented Jul 23, 2017

I think the final step in the given recipe should be:
git push
Without it, the remote part of your fork will still not be up-to-date. Right??

@caioleonhardt

This comment has been minimized.

Copy link

commented Aug 1, 2017

Thanks.

@charisTheo

This comment has been minimized.

Copy link

commented Aug 2, 2017

Thank you so much!!

@weitzhandler

This comment has been minimized.

Copy link

commented Aug 6, 2017

Thanks for sharing.
Would love to see this in the Visual Studio interface.

@DavidMS

This comment has been minimized.

Copy link

commented Aug 7, 2017

This didn't worked for me, the github repo still not up to date. And when i merged with master it didn't found any changes. Thankx anyway.

@DavidMS

This comment has been minimized.

Copy link

commented Aug 7, 2017

Fixed! I had my project connected to the origin instead of my github's repository in Visual Studio. I changed and it worked! I now can do it from Visual Studio with no command line arguments need.

@MounirHamani

This comment has been minimized.

Copy link

commented Aug 19, 2017

Thank you @duncombe.

@arzola

This comment has been minimized.

Copy link

commented Aug 22, 2017

If you don't have SSH access you can go with https 👍

git remote add upstream https://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git

@nitin1706

This comment has been minimized.

Copy link

commented Aug 22, 2017

Thanks. It helped.

@rujesh

This comment has been minimized.

Copy link

commented Aug 30, 2017

Great. Also, thank you @duncombe for your different approach.

@ludoo0d0a

This comment has been minimized.

Copy link

commented Sep 4, 2017

Thanks ! Solved my problem and it helps me to understand better branching concept ;) !

@petzi53

This comment has been minimized.

Copy link

commented Sep 6, 2017

Another thank you!! I googled this problem and found very different and much more complicated solutions. Besides those solutions have used 'rebase' e.g. have rewritten history. Your solution is simple - so that even I as a newbie to Git and Github can understand it. And: It works!

@DickensGDC

This comment has been minimized.

Copy link

commented Sep 21, 2017

I just want to say THANKS to you. I am new to make my little contribution to some awesome open source projects, and it solved my problem, much thanks.

@qm3ster

This comment has been minimized.

Copy link

commented Sep 21, 2017

@vlad-light did you push to your repository after this?

@robiXxu

This comment has been minimized.

Copy link

commented Sep 25, 2017

Thank you!

@franfacchini

This comment has been minimized.

Copy link

commented Oct 11, 2017

Tks!

@arvchristos

This comment has been minimized.

Copy link

commented Oct 13, 2017

This is great and simple. Thanks a lot

@EthraZa

This comment has been minimized.

Copy link

commented Oct 18, 2017

Make my day

@buoyantair

This comment has been minimized.

Copy link

commented Oct 21, 2017

This was helpful!

@SuperOP535

This comment has been minimized.

Copy link

commented Oct 21, 2017

Thanks

@dhirajpatra

This comment has been minimized.

Copy link

commented Oct 23, 2017

Better to use : git pull --rebase upstream master [for clean repo history] after add and fetch remote.

Regards

@mikeyc7m

This comment has been minimized.

Copy link

commented Oct 30, 2017

can this be done via the github website interface, rather than downloading the whole repository to a local?

@hemangshah

This comment has been minimized.

Copy link

commented Oct 31, 2017

Can someone tell how to do it with Github Desktop app for Mac?

@ewoks

This comment has been minimized.

Copy link

commented Nov 1, 2017

Guess I can't make PR for gist,no @CristinaSolana ? If not here is my teeny-tiny suggestion
https://gist.github.com/ewoks/63a4153577bdf58a69ba3a7c1f3ccdfb

@salah-mohammed

This comment has been minimized.

Copy link

commented Nov 14, 2017

how install forked as pod when add to my project

@meg7mal

This comment has been minimized.

Copy link

commented Nov 22, 2017

This is great thanks! In addition, I had to merge the upstream branch I was tracking to the equivalent branch in my local fork repo which @grabcode helped with by linking to https://help.github.com/articles/syncing-a-fork/

@mabelvj

This comment has been minimized.

Copy link

commented Dec 1, 2017

Great! Quite useful! Thanks!

@WarenGonzaga

This comment has been minimized.

Copy link

commented Dec 1, 2017

Thanks for this!

@sergeyguzhev

This comment has been minimized.

Copy link

commented Dec 15, 2017

Thank you, Cristina!

@Zibri

This comment has been minimized.

Copy link

commented Dec 29, 2017

is it possible to do it from the website directly?

@CCS86

This comment has been minimized.

Copy link

commented Dec 30, 2017

I'm wondering the same thing.

Also, what about selectively accepting/rejecting changes from the master to your fork?

@Rhialto

This comment has been minimized.

Copy link

commented Jan 1, 2018

Does this work for all branches, or only for master (I suspect this because master is mentioned in the command)?
What if I made a fresh branch to keep my changes on? (This seems to be recommended, I read somewhere). In this case all original upstream branches should simply fast-forward and only on my own changes branch there would be merges.

@YuRaNnNzZZ

This comment has been minimized.

Copy link

commented Jan 2, 2018

Thanks!

@ThatsGobbles

This comment has been minimized.

Copy link

commented Jan 19, 2018

Thank you Cristina, this was both very helpful and short and sweet. Much appreciated!

@rakeshhny

This comment has been minimized.

Copy link

commented Jan 22, 2018

In our organization we use Atlassian Stash Software for managing remote repositories.

We fork the upstream repository and keep the forked repository in auto-sync with upstream repository so that all approved/valid changes into upstream repository will automatically flow to all the forked repository.

With this I do not have to manually update my forked remote repository.

All I have to do is just pull latest from forked master into local master.

Is there a way on github to achieve the same?

@Eugene-Y

This comment has been minimized.

Copy link

commented Jan 26, 2018

thanks a bunch :)

@bartlettpsj

This comment has been minimized.

Copy link

commented Jan 31, 2018

Rakeshhny - there a fork syncing feature of github or GitLab enterprise, but not for gitlab community edition.

My company moved from stash to gitlab community and ever since I’ve missed that feature. Management was so much simpler.

Also the gitlab fork syncing feature isn’t as good as stash as it only does it every hour but I recall stash was immediate.

Just remember to pull from upstream before starting a new branch in your fork.

@gowthamkaruturi

This comment has been minimized.

Copy link

commented Feb 5, 2018

thanks a lot .

@sankar6

This comment has been minimized.

Copy link

commented Feb 6, 2018

thanks

@CDawg

This comment has been minimized.

Copy link

commented Feb 15, 2018

There are no responses to people still having an issue with this NOT working. There is definitely a clear bug that people are having following all the guides.
My forked local branch is NOT reflecting the original master. github says this master is 86 commits behind master. When I choose Compare it says that there is nothing to compare.
I have followed: https://help.github.com/articles/configuring-a-remote-for-a-fork/
I have followed: https://help.github.com/articles/syncing-a-fork/
My local fork STILL says Already up to date. Yet clearly the Master branch is far beyond my local fork.

If all else fails, you will have to "rebase" or delete your local repo and fork the origin all over again.

@hijxf

This comment has been minimized.

Copy link

commented Feb 16, 2018

thanks!

@CaDs

This comment has been minimized.

Copy link

commented Mar 3, 2018

thanks a lot

@pursonchen

This comment has been minimized.

Copy link

commented Mar 4, 2018

You can use my shell script to synchronize, welcome everyone to correct. https://github.com/pursonchen/sync-fork.git

@pharzath

This comment has been minimized.

Copy link

commented Mar 14, 2018

thanks

@e18r

This comment has been minimized.

Copy link

commented Mar 14, 2018

thanks

@aliradd

This comment has been minimized.

Copy link

commented Mar 15, 2018

Have I misunderstood something? is it not much easier to use the following:
https://help.github.com/articles/configuring-a-remote-for-a-fork/
thanks.

@fernandesGabriel

This comment has been minimized.

Copy link

commented Mar 16, 2018

Thanks a lot

@GarnetSunset

This comment has been minimized.

Copy link

commented Mar 20, 2018

Just dropping a big old thanks here :)

@xeniorac

This comment has been minimized.

Copy link

commented Apr 2, 2018

Thanks a ton for saving!

@RatnadeepBiswakarma

This comment has been minimized.

Copy link

commented Apr 3, 2018

I have forked a repository and I want to update my fork with the original repository how to do that?

@yangbodong22011

This comment has been minimized.

Copy link

commented Apr 6, 2018

@RatnadeepBiswakarma

git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
git rebase upstream master
@yanshengjia

This comment has been minimized.

Copy link

commented Apr 8, 2018

Thanks!

@Fogetti

This comment has been minimized.

Copy link

commented Apr 8, 2018

Cool thanks!

@geloumil

This comment has been minimized.

Copy link

commented Apr 14, 2018

thanks :)

@t151848p

This comment has been minimized.

Copy link

commented Apr 22, 2018

Danke!

@sonyakc

This comment has been minimized.

Copy link

commented May 2, 2018

Awesome this is great. Thank you!

@otherpirate

This comment has been minimized.

Copy link

commented May 4, 2018

Thanks!

@arisliang

This comment has been minimized.

Copy link

commented May 8, 2018

I find this is easier to grasp than the github documentation. Just remember to push after the pull, which should probably be the step 4 of the gist.

@spik3s

This comment has been minimized.

Copy link

commented May 28, 2018

That was so easy. Thanks!

@timoteoponce

This comment has been minimized.

Copy link

commented Jun 1, 2018

Still very useful, thanks @CristinaSolana!!

@lixzhang

This comment has been minimized.

Copy link

commented Jun 1, 2018

Thanks!

@omidnasri

This comment has been minimized.

Copy link

commented Jun 2, 2018

That was so easy. Thanks.

@danielmbicalho

This comment has been minimized.

Copy link

commented Jun 21, 2018

Easy. Thank you

@Dhiraj240

This comment has been minimized.

Copy link

commented Jun 22, 2018

Thank You.It made my day.

@sonfack

This comment has been minimized.

Copy link

commented Jun 24, 2018

Thanks very much. it works !

@seleregb

This comment has been minimized.

Copy link

commented Jul 4, 2018

works like a charm :)

@komputronika

This comment has been minimized.

Copy link

commented Jul 6, 2018

Thanks!

@edufonseca

This comment has been minimized.

Copy link

commented Jul 9, 2018

awesome!

@alexivkin

This comment has been minimized.

Copy link

commented Jul 10, 2018

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.

@brunobc182

This comment has been minimized.

Copy link

commented Jul 13, 2018

Thanks for share! 👍

@mleszcz

This comment has been minimized.

Copy link

commented Jul 17, 2018

👍

@MartinVNavarro

This comment has been minimized.

Copy link

commented Jul 17, 2018

So easy to follow, thank you so much 👍

@aparnap08

This comment has been minimized.

Copy link

commented Jul 18, 2018

Thanks for making this so simple. 👍

@derrick-gopher

This comment has been minimized.

Copy link

commented Jul 19, 2018

I realized that the merges happened but the branches from the original repository were not updated, run this bash script code to update the branches.

for branch in $(git ls-remote --heads upstream|sed 's#^.*refs/heads/##'); do git push origin refs/remotes/upstream/$branch:refs/heads/$branch; done

@CristinaSolana

This comment has been minimized.

Copy link
Owner Author

commented Jul 30, 2018

Glad this has helped everyone. Somehow I missed all the comments until now. :)

@terrysky718

This comment has been minimized.

Copy link

commented Aug 5, 2018

This is brilliant and immensely helpful! Thanks so much indeed.

@thiagoaugusto

This comment has been minimized.

Copy link

commented Aug 15, 2018

Thanks, Cristina! Helped me a lot.

@w3bn00b

This comment has been minimized.

Copy link

commented Aug 31, 2018

really thanks :P

@kanolato

This comment has been minimized.

Copy link

commented Sep 2, 2018

thanks!

@quintanilhaedu

This comment has been minimized.

Copy link

commented Sep 2, 2018

Thanks so much for this!

@Soundharyaam

This comment has been minimized.

Copy link

commented Sep 17, 2018

Thank you!

@cdobs

This comment has been minimized.

Copy link

commented Oct 2, 2018

Much appreciated!

@zimmertr

This comment has been minimized.

Copy link

commented Oct 15, 2018

Thanks!

@ghost

This comment has been minimized.

Copy link

commented Oct 19, 2018

@metude You've just updated your local repo and need to push your changes:

git push

Thanks, this worked

@aboutlucyl

This comment has been minimized.

Copy link

commented Oct 22, 2018

Thanks so much

@Ishaan28malik

This comment has been minimized.

Copy link

commented Nov 10, 2018

Thanks for this I learned it today @CristinaSolana

@Brambor

This comment has been minimized.

Copy link

commented Nov 14, 2018

Thank you! "Díky!"

@romch007

This comment has been minimized.

Copy link

commented Nov 18, 2018

Thanks ! 👍

@dflourusso

This comment has been minimized.

Copy link

commented Nov 21, 2018

Thanks, very helpful

@hanishassim

This comment has been minimized.

Copy link

commented Nov 23, 2018

I'm forking this article about fork =)

@AaronLiuIsCool

This comment has been minimized.

Copy link

commented Dec 6, 2018

Isn't "git rebase upstream/master" is better option than "git pull upstream master" ? This will work properly even if the current branch has few commits extra than in the upstream master.

I like this more

@Skura23

This comment has been minimized.

Copy link

commented Dec 17, 2018

How to do this on browser?

@pkgh

This comment has been minimized.

Copy link

commented Dec 19, 2018

A workaround for the website, NOT identical to the proper rebase: https://www.sitepoint.com/quick-tip-sync-your-fork-with-the-original-without-the-cli/ . After doing that you are 1 commit ahead of the original master.

@the-nose-knows

This comment has been minimized.

Copy link

commented Mar 9, 2019

Some of these steps need to be changed for HTTPS. Here's my re-write of the original for HTTPS:

HTTPS Instructions

Command-line Instructions

1. Clone your fork:

git clone https://github.com/$my_username/$repo_name

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

cd $repo_name
git remote add upstream https://github.com/$origin_fork/$repo_name.git
git fetch upstream

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

git pull upstream $branch_name

Real Example for command-line

You'll need to fork pandas-dev/pandas if you want to follow along. I'm not associated with them; I just chose a random repo I already had forked from the front-page.

git clone https://github.com/pandas-dev/pandas
cd pandas
git remote add upstream https://github.com/pandas-dev/pandas.git
git fetch upstream
git checkout master
git pull upstream master
git add -A
git commit -m "Sync my pandas master w/ pandas-dev master branch"
git push origin master

Browser Instructions

  1. Go to this URL: https://github.com/$my_username/$repo_name/compare/$branch_name...$origin_fork:$branch_name
  2. Click on "Create pull request"
  3. Add a title. I'd just call it upstream sync, personally
  4. Click on the new "Create pull request" button
  5. Scroll to the bottom
  6. Merge the pull request
    a. If you want to keep the commit history, just click "Merge pull request", then "Confirm merge"
    b. If you just want the code changes and only have a single commit to merge, click on the dropdown for "Merge pull request", select "Squash and Merge", then click on "Confirm Squash and Merge"
    c. If you want to rebase, have fun with that :) jk! Do pretty much the same thing as 6b but use the Rebase options

Alternative browser instructions

  1. From your fork's repo, click on "New pull request"
  2. Click on "compare across forks"
  3. On the left-hand side, select your fork
  4. Click on "compare across forks" again
  5. On the right-hand side, select the origin fork
  6. Follow steps #2 through #6 in the Browser Instructions section above this one

Real example for browser

While I can't really give you a "real" example for this beyond a screenshot, here's what I used for Mozilla's DeepSpeech sync to master:

https://github.com/the-nose-knows/DeepSpeech/compare/master...mozilla:master

browser

@karnadii

This comment has been minimized.

Copy link

commented Mar 18, 2019

wow this is really helpful, thanks

@Felipesdeveloper

This comment has been minimized.

Copy link

commented Mar 19, 2019

Thanks!!

@zimmertr

This comment has been minimized.

Copy link

commented Mar 22, 2019

When you make a buttload of changes to a fork and then realize you never caught it up to master and have to deal with 10,000 merge conflicts.

@dmtrkl

This comment has been minimized.

Copy link

commented Mar 24, 2019

Why to do fetch before pull?

@PasinduSandakelum

This comment has been minimized.

Copy link

commented May 17, 2019

Well ! It is working.. Thanks for your help..

@pangteypiyush

This comment has been minimized.

Copy link

commented Jun 17, 2019

Either git fetch upstream then git merge upstream master
or directly git pull upstream master
It does not make sense to pull after fetching remotes.

@Fanatic-Coder

This comment has been minimized.

Copy link

commented Jun 27, 2019

Isn't "git rebase upstream/master" is better option than "git pull upstream master" ? This will work properly even if the current branch has few commits extra than in the upstream master.

same thought. I've saw the "git rebase" from another tutorial, for the same thing. I have the same question.

@retomi

This comment has been minimized.

Copy link

commented Aug 20, 2019

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.