Remove Untracked Files With Git

Max Rosin

When working with Git I sometimes end up with a lot of untracked local files that I want to get rid of. For example, compiling things and testing around can create more stuff than expected or a git reset origin/master rolling back a lot of commits can leave a bunch of leftovers. To me this happens a few times a year and each time I realize that I forgot how I solved it last time. The answer is: git clean.

  • git clean -n Dry-run, show what would be deleted
  • git clean -f Really delete it
  • git clean -d Recurse into untracked directories

For me this usually means git clean -f -d and I am done. For more options check out the man page.

Max Rosin

I am a Systems Engineer from Germany. In my personal time I like to tinker with all kinds of technologies, some of it is available here at my blog. In my professional life I work a lot with Kubernetes and monitoring systems. Occasionally I give workshops about Kubernetes and conference talks about my work.
If you want to talk about one of my posts, feel free to reach out via Twitter.