Remove untracked files from git repository

Lets say you added 5 new files in your repository and for some reason you don’t need them anymore and want to remove.

There is a magic command which will work for you which is
git clean [options] [path]

There are some useful options available with this command.
1) --dry-run: It will not remove anything, just show what would be done
2) -d: Remove untracked directories in addition to untracked files.
3) -X: Remove only files ignored by git
4) -x: It will remove ignored as well non-ignored files by git.

Examples:
git clean -f -x
git clean -f -X

(If the git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f or –dry-run.)