git: Remove Untracked Files

By  on  

I've always said that I know just enough about git to get the job done, but also do something destructive. Nothing embodies that more than my recent mistake. I somehow found a git repository full of untracked files and git stash wouldn't fix it. Desperation led me to learning how to remove all untracked files, the same way hg purge does for mercurial.

To remove untracked files and directories, you can execute:

# Remove untracked directories
git clean -fd

# Remove only untracked files
git clean -fX

There you have it -- you've removed your untracked files. The dangerous side? It will also delete files hidden by .gitignore when you run a git status. Be careful when removing untracked files!

Recent Features

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    MooTools FontChecker Plugin

    There's a very interesting piece of code on Google Code called FontAvailable which does a jQuery-based JavaScript check on a string to check whether or not your system has a specific font based upon its output width. I've ported this functionality to MooTools. The MooTools...

  • By
    Geolocation API

    One interesting aspect of web development is geolocation; where is your user viewing your website from? You can base your language locale on that data or show certain products in your store based on the user's location. Let's examine how you can...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!