Undoing mistakes in GitHub

I accidentally committed some changes to my master branch on a forked GitHub repo (exercism/python, if you're interested) and pushed them to my fork. I needed a way to undo these changes, so I did the following:

  1. Add the upstream repository (the place you forked from): git remote add upstream <repo-address>
  2. Checkout master: git checkout master
  3. Hard reset (local changes are lost): git reset --hard upstream/master
  4. Pull upstream: git pull upstream master
  5. Forcefully push the repo to GitHub: git push --force origin master

There might be a better way to do this, but this way seems to have worked for me with no unexpected side-effects.