I forked a repository on Github. I\'ve made some minor changes and submitted pull requests to the upstream, but along the way my fork has become so mangled I\'m unable to ge
Step 1: Pull upstream changes
It's recommended to add the upstream repo as "upstream" as explained on the Fork a Repo page:
git pull --rebase upstream master
The --rebase
option places your changes on top of the latest commit without merges.
Step 2: (Optional) Merge your commits into 1 commit
git reset --soft upstream/master
This command will "undo" all your commits, but won't change the files. So you can commit all your changes in a single commit.
git commit -a
Step 3: Check & test your changes
To show the changes use a GUI like the built-in gitk
, Sourcetree, TortoiseGit or Tower (paid), etc.
Step 4: Push
git push
will throw an error, because the push would change the target repository's history.
If you're confident the changes shown in step 3 are correct then push with "-f"
git push -f origin master
Additional information
The command to add a remote is:
git remote add upstream git://github.com/[username]/[project].git
You can also also pull from a direct URL:
git pull --rebase git://github.com/[username]/[project].git
But then you'll need the hash of the latest upstream commit instead of "upstream/master" in the other steps.