directory

Git – Remove untracked files matching a pattern

Solution

$ git clean [-n] -f <path>...

Example

Run:

$ git clean -n -f *.json

to remove all untracked json files.

Important note

Always use -n or --dry-run before running the command.