Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Force your forked repo to be the same as upstream.
git fetch upstream
git reset --hard upstream/master
@anaisbetts

This comment has been minimized.

Copy link

anaisbetts commented Mar 4, 2012

Keep in mind, that this makes your repo look exactly like upstream - if you have commits, they will be eaten! If you want to update to upstream (but still keep your commits), you want git merge upstream/master. If you want to start a new patch based on upstream, the best way to do it is git checkout -b my-new-feature upstream/master

Of course, this all expects you have a remote named upstream, which you can create by doing git remote add upstream https://[upstream guy's repo url]

@anaisbetts

This comment has been minimized.

Copy link

anaisbetts commented Mar 4, 2012

(Just to clarify, the term 'upstream' means the person you forked from)

@dterweij

This comment has been minimized.

Copy link

dterweij commented Feb 4, 2014

[danny@server01 kloxo]$ git fetch upstream
[danny@server01 kloxo]$ git reset --hard upstream/dev
fatal: ambiguous argument 'upstream/dev': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'

And now?

@pepa65

This comment has been minimized.

Copy link

pepa65 commented Feb 8, 2017

So this works great locally, but how can I get my github repo master branch to be the same as locally/upstream??

@shacker

This comment has been minimized.

Copy link

shacker commented Feb 18, 2017

@pepa65
git push origin master --force

@JerryGoyal

This comment has been minimized.

Copy link

JerryGoyal commented Nov 1, 2017

complete git commands would be like this:

git remote add upstream https://github.com/some_user/some_repo
git fetch upstream
git checkout master
git reset --hard upstream/master  
git push origin master --force
@chsuditi

This comment has been minimized.

Copy link

chsuditi commented Dec 8, 2017

worked for me..thnx

@bls1999

This comment has been minimized.

Copy link

bls1999 commented Feb 14, 2018

@JerryGoyal PRAISE YOU

@azzamsa

This comment has been minimized.

@garrettbear

This comment has been minimized.

Copy link

garrettbear commented May 23, 2018

@JerryGoyal thank you kind sir

@amamsaang

This comment has been minimized.

Copy link

amamsaang commented Sep 5, 2018

👍

@jtr13

This comment has been minimized.

Copy link

jtr13 commented Dec 10, 2018

Why not just delete the fork and start over?

@ravi-bharadwaj

This comment has been minimized.

Copy link

ravi-bharadwaj commented Jan 17, 2019

@JerryGoyal, Thank you!

@PatMyron

This comment has been minimized.

Copy link

PatMyron commented Feb 20, 2019

@jtr13 might have Github issues you want to keep around

@kbintermx

This comment has been minimized.

Copy link

kbintermx commented May 1, 2019

So how about the opposite situation?

What if the history was changed on a fork but it needs to be asserted as the upstream master?
ie, the error: "There isn’t anything to compare." A:master and B: "are entirely different commit histories."

Precondition: Working on the fork

git fetch origin
git checkout master
git reset --hard origin/master
git remote add upstream https://github.com/some_user/A
git push upstream master --force

Would this have expected results?

@vaibhavhrt

This comment has been minimized.

Copy link

vaibhavhrt commented May 20, 2019

git push --force is a required step too to update your remote i.e. origin/master after the hard reset

@michaelshiyu

This comment has been minimized.

Copy link

michaelshiyu commented Jun 28, 2019

Works like a charm. Thanks!

@108krohan

This comment has been minimized.

Copy link

108krohan commented Jul 23, 2019

This is so great, thank you! @JerryGoyal

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.