-
Star
(152)
You must be signed in to star a gist -
Fork
(24)
You must be signed in to fork a gist
-
-
Save glennblock/1974465 to your computer and use it in GitHub Desktop.
git fetch upstream | |
git reset --hard upstream/master |
@JerryGoyal, Thank you!
@jtr13 might have Github issues you want to keep around
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?
git push --force
is a required step too to update your remote i.e. origin/master after the hard reset
Works like a charm. Thanks!
This is so great, thank you! @JerryGoyal
what if there are new files in my commit that I want to keep, but changes the upstream made to files that I already have that I also want. When I try to merge upstream, I receive an error: files would be overwritten by merge. But I want them to be overwritten.
can we do this from the GitHub UI?
How can I force users to pull from upstream after a major upgrade of the source code. I have PR validation in place (Jenkins) and they are using the old validation code (python).. ?
Works perfectly. Thanks for the tip.
you may need to also push tags
git push --tags
other variations:
git reset --hard upstream/master
git reset --hard upstream/main
git reset --hard upstream/development
👍
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
Perfect! Thank you!
So this works great locally, but how can I get my GitHub repo master branch to be the same as locally/upstream??
This is possible with a one-liner that doesn't require downloading anything...
For anyone interested in syncing your GitHub-hosted fork directly (without cloning locally first) you can do this using the GitHub CLI:
gh repo sync owner/cli-fork -b BRANCH-NAME
Why not just delete the fork and start over?