DEV Community

olistik
olistik

Posted on • Edited on

2

Delete all untracked files in git

Suppose that you've just done a git checkout -f to cleanup your local modifications.

New files added will slip out of the previous command, because they're treated by git as "untracked".

Here's a one-liner to get rid of these little fellas (requires a Ruby interpreter, because I <3 Ruby):

git status \
  --untracked-files=all \
  --no-column \
  --short | \
  rm $(ruby -e "puts STDIN.read.lines.map(&:split).map(&:last).join(' ')")
Enter fullscreen mode Exit fullscreen mode

Done

Image source

Update: as @kwstannard rightfully pointed out in the comments, there's also the prettier git-clean.

Top comments (2)

Collapse
 
kwstannard profile image
Kelly Stannard

Nice! You may be interested in the git-clean command as well.

Collapse
 
olistik profile image
olistik

You're definitely right. I didn't know it existed. ^_^'

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more