Git 2 reference · Undoing Changes

git clean Command (Git)

Remove untracked files from the working tree; always preview with -n first.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git clean -n|-f [-d] [-x]

Parameters

ParameterDescription
-n Dry run: show what would be removed.
-f Actually remove.
-d Include directories.
-x Also remove ignored files.

Examples

Preview
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
mkdir build; touch build/app.o tmp.log
git clean -n -d

Output

Would remove build/
Would remove tmp.log

Run this on your computer — see “Get Started” for setup.

Ignored files need -x
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo '*.log' > .gitignore; git add .gitignore; git commit -q -m ignore
touch a.tmp debug.log
git clean -f -q; ls
git clean -f -x -q; ls

Output

README.md
debug.log
README.md

Run this on your computer — see “Get Started” for setup.

Was this page helpful?