How to remove local untracked files from the current Git branch

Well, the short answer as per the Git Documents is git clean

How to remove local untracked files from the current Git branch

Well, the short answer as per the Git Documents is git clean

If you want to see which files will be deleted you can use the -n option before you run the actual command:

git clean -n

Then when you are comfortable (because it will delete the files for real!) use the -f option:

git clean -f

Here are some more options for you to delete directories, files, ignored and non-ignored files

  • To remove directories, run git clean -f -d or git clean -fd
  • To remove ignored files, run git clean -f -X or git clean -fX
  • To remove ignored and non-ignored files, run git clean -f -x or git clean -fx

Note the case difference on the X for the two latter commands.

If you use GIT regularly, I recommend to get this book and have it on your desk:

Pro Git
Pro Git (Second Edition) is your fully-updated guide to Git and its usage in the modern world. Git has come a long way…www.amazon.com

If you liked this article, click the👏 below so other people will see it here on Medium.

Let’s be friends on Twitter. Happy Coding :)

Cheers!