Git Remove Untracked Files using Command

In order to remove untracked files in Git make use of the git clean command with -i option for interactive mode.

Example:
% git clean -i -f


Would remove the following item:
  HelloWorld.java
  .temp
  index.html
*** Commands ***
    1: clean          
    2: filter by pattern
    3: select by numbers
    4: ask each
    5: quit
    6: help
What now> 1
Removing HelloWorld.java
Removing .temp
Removing index.html
Git Remove Untracked Files using Command
Some Options:
-i (--interactive) --> Interactive Mode
-f (--force) --> Force
-d --> Include directories
-n (--dry-run) --> dry run
-q (--quiet) only report if errors

Read More: https://git-scm.com/docs/git-clean#Documentation/git-clean.txt---force


This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Ventura 13.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!