Git Reset Demystified: How to Restore Your Working Directory to Match the Master Remote Branch Exactly

Quick little tutorial here, mostly for my own personal reference, on how to restore your local working directory to match a remote master branch. Take this scenario for instance, you’re working on a project for work, maybe as a junior developer working on your first professional project, and you make a bunch of changes to your working directory that you want to throw away, and restore your project to match the remote master branch. Here are your four magic commands:

$ git checkout master

$ git fetch origin

$ git reset --hard origin/master

$ git clean -df