Undo unsaved changes in Git

If you did a git checkout on a branch and found conflicts or, in general, you did some changes in your local repo, you can undo everything and go back to the previous state with these steps:

git reset --hard HEAD

This command reverts everything to the state of the last commit and discards local changes, including conflicting ones.

or better

git reset --hard origin/nome-del-branch

If there are any untracked files that are causing problems, you can delete them with:

git clean -df

Just a tricky, if you want to go back to the previous branch, just do this:

git checkout -