How do I discard unstaged changes in Git?

Summary

  1. Stashing files (Can recover later)
git stash save --keep-index
  1. Cleaning files (Cannot recover later)
git clean -fd
git checkout -- .

Details

Stashing Files

  1. git stash saves files in a stashed list of temporary repository edits.
git stash save --keep-index
  1. After stashing, you can drop that stash with a git stash drop command if you like.

Cleaning Files

  1. git clean removes all untracked files (warning: while it won’t delete ignored files mentioned directly in .gitignore, it may delete ignored files residing in folders) and git checkout clears all unstaged changes.
git clean -fd
git checkout -- .

Documentation