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

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

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

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

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

@ncrash ncrash commented May 7, 2014

Thanks!!

@vladimir-light

This comment has been minimized.

Copy link

@vladimir-light vladimir-light 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

@sudoer sudoer commented Feb 16, 2015

Thanks for sharing! I'm learning by doing.

@timmaybrown

This comment has been minimized.

Copy link

@timmaybrown timmaybrown commented Jun 26, 2015

Thank you so much!

@mtjhax

This comment has been minimized.

Copy link

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

@SkyzohKey SkyzohKey commented Apr 2, 2016

Thanks. Saved my day. :3

@NitroBAY

This comment has been minimized.

Copy link

@NitroBAY NitroBAY commented Apr 8, 2016

Thanks

@wolf99

This comment has been minimized.

Copy link

@wolf99 wolf99 commented May 12, 2016

Awesome, thanks!

@vis4573

This comment has been minimized.

Copy link

@vis4573 vis4573 commented Jun 1, 2016

Thank You !

@NexusInk

This comment has been minimized.

Copy link

@NexusInk NexusInk commented Jun 24, 2016

Git also does this via 'sync' on Desktop.

@evrpg

This comment has been minimized.

Copy link

@evrpg evrpg commented Sep 10, 2016

Thank you working just fine.

@zbyna

This comment has been minimized.

Copy link

@zbyna zbyna commented Sep 17, 2016

Thanks, I got it finally 😃

@andreasblueher

This comment has been minimized.

Copy link

@andreasblueher andreasblueher commented Oct 12, 2016

Thank you very much! 👍

@xCyborg

This comment has been minimized.

Copy link

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

@robincher robincher commented Dec 12, 2016

Thanks for the help! It's working right here

@mamakancha

This comment has been minimized.

Copy link

@mamakancha mamakancha commented Dec 15, 2016

Thanks. Helped me a lot :)

@isabellerichard

This comment has been minimized.

Copy link

@isabellerichard isabellerichard commented Jan 13, 2017

Top 👍

@conorbmurphy

This comment has been minimized.

Copy link

@conorbmurphy conorbmurphy commented Jan 17, 2017

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

@AdrianAntunez

This comment has been minimized.

Copy link

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

@mitchellkrogza mitchellkrogza commented Jan 28, 2017

works like a charm, thank you

@lucapierobon

This comment has been minimized.

Copy link

@lucapierobon lucapierobon commented Feb 5, 2017

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

@MajesticFalcon

This comment has been minimized.

Copy link

@MajesticFalcon MajesticFalcon commented Feb 6, 2017

Thank you

@mmccool

This comment has been minimized.

Copy link

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

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

@4leem 4leem commented Mar 23, 2017

Thanks! Work like a charm

@OtacilioN

This comment has been minimized.

Copy link

@OtacilioN OtacilioN commented Mar 25, 2017

Thank you so much!

@qct

This comment has been minimized.

Copy link

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

@pierx pierx commented Apr 27, 2017

Thanks

@blachawk

This comment has been minimized.

Copy link

@blachawk blachawk commented May 10, 2017

Thanks!

@mohamessi

This comment has been minimized.

Copy link

@mohamessi mohamessi commented May 11, 2017

Thanks you very mutch.

@david-sackstein

This comment has been minimized.

Copy link

@david-sackstein david-sackstein 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?
@quietcoding

This comment has been minimized.

Copy link

@quietcoding quietcoding commented May 21, 2017

Awesome, worked as intended.

Thanks!

@duncombe

This comment has been minimized.

Copy link

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

@Pradhvan Pradhvan commented Jun 12, 2017

Thanks !

@srxr

This comment has been minimized.

Copy link

@srxr srxr commented Jun 28, 2017

Thanks!

@jfeng10

This comment has been minimized.

Copy link

@jfeng10 jfeng10 commented Jul 4, 2017

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

@chathuralakmal

This comment has been minimized.

Copy link

@chathuralakmal chathuralakmal commented Jul 5, 2017

Thanks.

@jishnujayakumar

This comment has been minimized.

Copy link

@jishnujayakumar jishnujayakumar commented Jul 12, 2017

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

@azzamsa

This comment has been minimized.

Copy link

@azzamsa azzamsa commented Jul 19, 2017

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

@tuhinsharma121

This comment has been minimized.

Copy link

@tuhinsharma121 tuhinsharma121 commented Jul 19, 2017

Works fine!! Thanks!!

@pepa65

This comment has been minimized.

Copy link

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

@caioleonhardt caioleonhardt commented Aug 1, 2017

Thanks.

@charisTheo

This comment has been minimized.

Copy link

@charisTheo charisTheo commented Aug 2, 2017

Thank you so much!!

@weitzhandler

This comment has been minimized.

Copy link

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

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

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

@MounirHamani MounirHamani commented Aug 19, 2017

Thank you @duncombe.

@arzola

This comment has been minimized.

Copy link

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

@nitin1706 nitin1706 commented Aug 22, 2017

Thanks. It helped.

@rujesh

This comment has been minimized.

Copy link

@rujesh rujesh commented Aug 30, 2017

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

@ludoo0d0a

This comment has been minimized.

Copy link

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

@petzi53 petzi53 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!

@successgo

This comment has been minimized.

Copy link

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

@qm3ster qm3ster commented Sep 21, 2017

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

@robiXxu

This comment has been minimized.

Copy link

@robiXxu robiXxu commented Sep 25, 2017

Thank you!

@franfacchini

This comment has been minimized.

Copy link

@franfacchini franfacchini commented Oct 11, 2017

Tks!

@arvchristos

This comment has been minimized.

Copy link

@arvchristos arvchristos commented Oct 13, 2017

This is great and simple. Thanks a lot

@EthraZa

This comment has been minimized.

Copy link

@EthraZa EthraZa commented Oct 18, 2017

Make my day

@buoyantair

This comment has been minimized.

Copy link

@buoyantair buoyantair commented Oct 21, 2017

This was helpful!

@SuperOP535

This comment has been minimized.

Copy link

@SuperOP535 SuperOP535 commented Oct 21, 2017

Thanks

@dhirajpatra

This comment has been minimized.

Copy link

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

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

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

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

@salah-mohammed salah-mohammed commented Nov 14, 2017

how install forked as pod when add to my project

@meg7mal

This comment has been minimized.

Copy link

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

@mabelvj mabelvj commented Dec 1, 2017

Great! Quite useful! Thanks!

@WarenGonzaga

This comment has been minimized.

Copy link

@WarenGonzaga WarenGonzaga commented Dec 1, 2017

Thanks for this!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Dec 15, 2017

Thank you, Cristina!

@Zibri

This comment has been minimized.

Copy link

@Zibri Zibri commented Dec 29, 2017

is it possible to do it from the website directly?

@CCS86

This comment has been minimized.

Copy link

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

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

@YuRaNnNzZZ YuRaNnNzZZ commented Jan 2, 2018

Thanks!

@linclelinkpart5

This comment has been minimized.

Copy link

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

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

@Eugene-Y Eugene-Y commented Jan 26, 2018

thanks a bunch :)

@bartlettpsj

This comment has been minimized.

Copy link

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

@gowthamkaruturi gowthamkaruturi commented Feb 5, 2018

thanks a lot .

@sankar6

This comment has been minimized.

Copy link

@sankar6 sankar6 commented Feb 6, 2018

thanks

@CDawg

This comment has been minimized.

Copy link

@CDawg CDawg 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.

@jef

This comment has been minimized.

Copy link

@jef jef commented Feb 16, 2018

thanks!

@CaDs

This comment has been minimized.

Copy link

@CaDs CaDs commented Mar 3, 2018

thanks a lot

@pursonchen

This comment has been minimized.

Copy link

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

@pharzath pharzath commented Mar 14, 2018

thanks

@e18r

This comment has been minimized.

Copy link

@e18r e18r commented Mar 14, 2018

thanks

@aliradd

This comment has been minimized.

Copy link

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

@fernandesGabriel fernandesGabriel commented Mar 16, 2018

Thanks a lot

@GarnetSunset

This comment has been minimized.

Copy link

@GarnetSunset GarnetSunset commented Mar 20, 2018

Just dropping a big old thanks here :)

@xeniorac

This comment has been minimized.

Copy link

@xeniorac xeniorac commented Apr 2, 2018

Thanks a ton for saving!

@RatnadeepBiswakarma

This comment has been minimized.

Copy link

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

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

@yanshengjia yanshengjia commented Apr 8, 2018

Thanks!

@Fogetti

This comment has been minimized.

Copy link

@Fogetti Fogetti commented Apr 8, 2018

Cool thanks!

@geloumil

This comment has been minimized.

Copy link

@geloumil geloumil commented Apr 14, 2018

thanks :)

@t151848p

This comment has been minimized.

Copy link

@t151848p t151848p commented Apr 22, 2018

Danke!

@sonyakc

This comment has been minimized.

Copy link

@sonyakc sonyakc commented May 2, 2018

Awesome this is great. Thank you!

@otherpirate

This comment has been minimized.

Copy link

@otherpirate otherpirate commented May 4, 2018

Thanks!

@arisliang

This comment has been minimized.

Copy link

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

@spik3s spik3s commented May 28, 2018

That was so easy. Thanks!

@timoteoponce

This comment has been minimized.

Copy link

@timoteoponce timoteoponce commented Jun 1, 2018

Still very useful, thanks @CristinaSolana!!

@lixzhang

This comment has been minimized.

Copy link

@lixzhang lixzhang commented Jun 1, 2018

Thanks!

@omidnasri

This comment has been minimized.

Copy link

@omidnasri omidnasri commented Jun 2, 2018

That was so easy. Thanks.

@danielmbicalho

This comment has been minimized.

Copy link

@danielmbicalho danielmbicalho commented Jun 21, 2018

Easy. Thank you

@Dhiraj240

This comment has been minimized.

Copy link

@Dhiraj240 Dhiraj240 commented Jun 22, 2018

Thank You.It made my day.

@sonfack

This comment has been minimized.

Copy link

@sonfack sonfack commented Jun 24, 2018

Thanks very much. it works !

@seleregb

This comment has been minimized.

Copy link

@seleregb seleregb commented Jul 4, 2018

works like a charm :)

@komputronika

This comment has been minimized.

Copy link

@komputronika komputronika commented Jul 6, 2018

Thanks!

@edufonseca

This comment has been minimized.

Copy link

@edufonseca edufonseca commented Jul 9, 2018

awesome!

@alexivkin

This comment has been minimized.

Copy link

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

@brunobc182 brunobc182 commented Jul 13, 2018

Thanks for share! 👍

@mleszcz

This comment has been minimized.

Copy link

@mleszcz mleszcz commented Jul 17, 2018

👍

@MartinVNavarro

This comment has been minimized.

Copy link

@MartinVNavarro MartinVNavarro commented Jul 17, 2018

So easy to follow, thank you so much 👍

@aparnap08

This comment has been minimized.

Copy link

@aparnap08 aparnap08 commented Jul 18, 2018

Thanks for making this so simple. 👍

@derrick-gopher

This comment has been minimized.

Copy link

@derrick-gopher derrick-gopher 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

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

@terrysky718 terrysky718 commented Aug 5, 2018

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

@thiagoaugusto

This comment has been minimized.

Copy link

@thiagoaugusto thiagoaugusto commented Aug 15, 2018

Thanks, Cristina! Helped me a lot.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Aug 31, 2018

really thanks :P

@kanolato

This comment has been minimized.

Copy link

@kanolato kanolato commented Sep 2, 2018

thanks!

@Eduard0x6F

This comment has been minimized.

Copy link

@Eduard0x6F Eduard0x6F commented Sep 2, 2018

Thanks so much for this!

@Soundharyaam

This comment has been minimized.

Copy link

@Soundharyaam Soundharyaam commented Sep 17, 2018

Thank you!

@cdobs

This comment has been minimized.

Copy link

@cdobs cdobs commented Oct 2, 2018

Much appreciated!

@zimmertr

This comment has been minimized.

Copy link

@zimmertr zimmertr commented Oct 15, 2018

Thanks!

@ghost

This comment has been minimized.

Copy link

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

@aboutlucyl aboutlucyl commented Oct 22, 2018

Thanks so much

@Ishaan28malik

This comment has been minimized.

Copy link

@Ishaan28malik Ishaan28malik commented Nov 10, 2018

Thanks for this I learned it today @CristinaSolana

@Brambor

This comment has been minimized.

Copy link

@Brambor Brambor commented Nov 14, 2018

Thank you! "Díky!"

@romch007

This comment has been minimized.

Copy link

@romch007 romch007 commented Nov 18, 2018

Thanks ! 👍

@dflourusso

This comment has been minimized.

Copy link

@dflourusso dflourusso commented Nov 21, 2018

Thanks, very helpful

@hanishassim

This comment has been minimized.

Copy link

@hanishassim hanishassim commented Nov 23, 2018

I'm forking this article about fork =)

@AaronLiuIsCool

This comment has been minimized.

Copy link

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

@Skura23 Skura23 commented Dec 17, 2018

How to do this on browser?

@pkgh

This comment has been minimized.

Copy link

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

@the-nose-knows the-nose-knows 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

@karnadii karnadii commented Mar 18, 2019

wow this is really helpful, thanks

@Felipesdeveloper

This comment has been minimized.

Copy link

@Felipesdeveloper Felipesdeveloper commented Mar 19, 2019

Thanks!!

@zimmertr

This comment has been minimized.

Copy link

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

@dmtrkl dmtrkl commented Mar 24, 2019

Why to do fetch before pull?

@PasinduSandakelum

This comment has been minimized.

Copy link

@PasinduSandakelum PasinduSandakelum commented May 17, 2019

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

@pangteypiyush

This comment has been minimized.

Copy link

@pangteypiyush pangteypiyush 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.

@ioannis-xenakis

This comment has been minimized.

Copy link

@ioannis-xenakis ioannis-xenakis 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

@retomi retomi commented Aug 20, 2019

Thanks!!

@mbledkowski

This comment has been minimized.

Copy link

@mbledkowski mbledkowski commented Oct 1, 2019

Love it <3

@SalimGangji

This comment has been minimized.

Copy link

@SalimGangji SalimGangji commented Oct 4, 2019

Thank you very much!

@Jaseemck

This comment has been minimized.

Copy link

@Jaseemck Jaseemck commented Oct 15, 2019

Thank you...it helps a lot

@mohammadjkhan

This comment has been minimized.

Copy link

@mohammadjkhan mohammadjkhan commented Nov 18, 2019

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.
If you don't want to do a git pull and are trying to merge, then your git fetch should be followed by git merge

Here's what the git merge command would be if not doing a git pull in step 3:
git merge upstream/master master

Rebase moves or combines your local sequence of commits to a new base commit such that your local commits are reorganized on top of the latest changes fetched from upstream branch.

So if you want to rebase instead of merge, here's the command you would use in step 3:
git rebase upstream/master

If you want to fetch and rebase in one step:
git pull --rebase upstream master

@CristinaSolana

This comment has been minimized.

Copy link
Owner Author

@CristinaSolana CristinaSolana commented Nov 23, 2019

@mohammadjkhan step 3 is not meant to be done initially. It is meant for future when you want to get latest changes down the line.

@moh-hassan

This comment has been minimized.

Copy link

@moh-hassan moh-hassan commented Dec 24, 2019

Syncing your fork to the original repository via the browser using the compare button
Or via the commandline, to sync master (for other branch replace master with branch):

$ git fetch upstream
$ git checkout master
$ git merge upstream/master
$ git push origin master
@nocnoi

This comment has been minimized.

Copy link

@nocnoi nocnoi commented Jan 17, 2020

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?

If you want to pull a newly created upstream branch into your fork. Say the branch name is new-branch.
Step 1: get all upstream branches (including newly created ones)
git fetch upstream

Step 2: create a new local branch with the same name, pulling from the upstream branch
git branch -b new-branch upstream/new-branch

Step 3: push the new branch to origin so you keep your origin repo up-to-date
git push -u origin new-branch

@lightkun10

This comment has been minimized.

Copy link

@lightkun10 lightkun10 commented Feb 2, 2020

Thank you very much!

@Chadori

This comment has been minimized.

Copy link

@Chadori Chadori commented Feb 13, 2020

Thanks everyone!

@sarahqiao9

This comment has been minimized.

Copy link

@sarahqiao9 sarahqiao9 commented Feb 21, 2020

It works. Thanks!!!

@brandnewx

This comment has been minimized.

Copy link

@brandnewx brandnewx commented Feb 22, 2020

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

@CristinaSolana

This comment has been minimized.

Copy link
Owner Author

@CristinaSolana CristinaSolana commented Feb 22, 2020

@sourabhdeshmukh

This comment has been minimized.

Copy link

@sourabhdeshmukh sourabhdeshmukh commented Feb 26, 2020

Thanks it Worked for me. :)

@trillaxe

This comment has been minimized.

Copy link

@trillaxe trillaxe commented Feb 27, 2020

thank you!

@CompassTheSolution

This comment has been minimized.

Copy link

@CompassTheSolution CompassTheSolution commented Mar 5, 2020

@RatnadeepBiswakarma
git rebase upstream master

should be:

git rebase upstream/master

And it worked great for me, thanks!

@luisriverag

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

@pramodjodhani pramodjodhani commented May 4, 2020

Thanks a lot 👍

@RodolfoGS

This comment has been minimized.

Copy link

@RodolfoGS RodolfoGS commented Jul 26, 2020

Thanks!

@kxrob

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

@DahnJ DahnJ commented Aug 9, 2020

Thanks for this!

@ValentineDragan

This comment has been minimized.

Copy link

@ValentineDragan ValentineDragan commented Aug 17, 2020

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

@CristinaSolana

This comment has been minimized.

Copy link
Owner Author

@CristinaSolana CristinaSolana commented Aug 17, 2020

Glad you all are finding this helpful. :)

@zcmgyu

This comment has been minimized.

Copy link

@zcmgyu zcmgyu commented Oct 13, 2020

Update Oct 13, 2020:

git pull upstream main

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.