git clean -fd

Remove untracked files and directories from your git repository

Here's a breakdown of what each part of the command does:

  • git clean: This is the base command that's used to remove untracked files from your working directory. This is helpful for getting rid of build artifacts, merge residue, etc. that you haven't added to your Git repository.

  • -f or --force: The -f option stands for "force." Git clean will not actually remove files or directories unless this option is specified. This is a safety measure to prevent accidental deletion of important files.

  • -d: This option tells Git to remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. The -d option overrides this behavior.