Kaleem Ullah's Blog

Remove untracked files from git repository

Posted in git by Kaleem Ullah on August 10, 2011

Lets say you added 5 new files in your repository and for some reason you don’t need them anymore and want to remove.

There is a magic command which will work for you which is

git clean [options] [path]

There are some useful options available with this command.

1) --dry-run: It will not remove anything, just show what would be done
2) -d: Remove untracked directories in addition to untracked files.
3) -X: Remove only files ignored by git
4) -x: It will remove ignored as well non-ignored files by git.


git clean -f -x
git clean -f -X

(If the git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f or –dry-run.)

Tagged with: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: