PHPexp logo PHPexp

Force syncing a fork with git

Published on

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 your fork with the upstream repository. After force syncing, you can create a new branch which can be merged upstream without any merge conflicts.

Of course, by hard resetting you will lose all your changes! Make sure you only do this if you have nothing to lose.

Level up your Laravel deployments

If you aren't happy with your current deployment strategy for your Laravel apps, check out my premium deployment script.

Deploy with GitHub Actions Deploy with GitLab CI/CD