Here's a quick walkthrough to help you reset a local git branch to remote.

We'll begin with the following assumptions: you have a user branch that is tracking a remote/upstream, you have local edits that you want to discard and you want to reset local to the latest remote/upstream commit.

Confirm local changes

Make sure you know what changes you're about to lose. If you want to preserve anything for later, you can usestash:

  
  git status
  

Alternative: Clear files

Consider whether you can use a simple method to remove untracked files instead of reseting the branch. You can try git clean or checkout:

  
  git clean -f
  

Remove all untracked files.

  
  git checkout .
  

Remove all unstaged changes in my working tree.

Reset to the latest commit on remote / upstream

This will remove all local changes.

  
  git reset --hard HEAD
  

The result is the same as re-cloning the repository.

More reading related to git: