Force syncing a fork

If you have an outdated fork, you first need to sync it with the upstream repository before you can open up a new pull request. A foolproof but annoying solution to get an up-to-date fork is to delete your fork, and then re-fork it. Another approach is to properly sync your fork. However, the few times I've tried to do it the proper way, I usually ran into trouble, and ended up deleting my fork anyway.

An easier way to sync a fork, instead of learning how to do it the proper way, is to force it:

# If you haven't added the upstream repository yet
git remote add upstream [upstream URL]

git fetch upstream

git reset --hard upstream/master

git push --force

This syncs up your fork with the upstream repository. After force syncing, you can create a new branch which can be merged upstream without any merge conflicts.

Keep in mind that by hard resetting you will lose all your changes! Only use this approach if you have no changes that you want to keep.