git Verified current stable Not installed? Version Control

Git / Force Delete Untracked And Excluded Files

Force Delete Untracked And Excluded Files

Use 'git clean -fx' to forcefully remove untracked and excluded files from your Git repository.

$
Terminal
git clean -f -x

When To Use

Cleaning up untracked files before a production release.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Removing untracked files:
  deleted:    build/output.log
  deleted:    temp/cache

Done!

Command Breakdown

What each part is doing

git
Base Command
The executable that performs this operation. Here it runs Git before the shell applies any redirect operators.
-f
f| force
The value supplied for f| force.
-f
Command Option
Tool-specific option used by this command invocation.
-x
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Open your terminal and navigate to your Git repository.

  2. Step 2

    Run the command: git clean -fx to remove untracked and excluded files.

  3. Step 3

    Verify the changes by checking the status with git status.

Alternative Approaches

Comparable commands in other tools

Alternative version control tools for the same job.