Git – How To Discard All Local Changes / Commits

This post will show you how to discard all local changes in your git repository. If you have got stuck with this problem, this post is for you.

To do this, let’s follow the following 2 steps:


1. Remove untracked directories in addition to untracked files

git clean -fd

This git clean command will remove all new directories.


2. Reset all changes in your project files

git reset --hard origin/<branch_name>

Don’t forget to change <branch_name> to your working branch. For example, if you are working on the master branch, the command will look like this:

git reset --hard origin/master