git: Remove Untracked Files

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 post git: Remove Untracked Files appeared first on David Walsh Blog.

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!

The post git: Remove Untracked Files appeared first on David Walsh Blog.


Print Share Comment Cite Upload Translate
APA
David Walsh | Sciencx (2024-03-28T22:04:59+00:00) » git: Remove Untracked Files. Retrieved from https://www.scien.cx/2020/11/19/git-remove-untracked-files/.
MLA
" » git: Remove Untracked Files." David Walsh | Sciencx - Thursday November 19, 2020, https://www.scien.cx/2020/11/19/git-remove-untracked-files/
HARVARD
David Walsh | Sciencx Thursday November 19, 2020 » git: Remove Untracked Files., viewed 2024-03-28T22:04:59+00:00,<https://www.scien.cx/2020/11/19/git-remove-untracked-files/>
VANCOUVER
David Walsh | Sciencx - » git: Remove Untracked Files. [Internet]. [Accessed 2024-03-28T22:04:59+00:00]. Available from: https://www.scien.cx/2020/11/19/git-remove-untracked-files/
CHICAGO
" » git: Remove Untracked Files." David Walsh | Sciencx - Accessed 2024-03-28T22:04:59+00:00. https://www.scien.cx/2020/11/19/git-remove-untracked-files/
IEEE
" » git: Remove Untracked Files." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2020/11/19/git-remove-untracked-files/. [Accessed: 2024-03-28T22:04:59+00:00]
rf:citation
» git: Remove Untracked Files | David Walsh | Sciencx | https://www.scien.cx/2020/11/19/git-remove-untracked-files/ | 2024-03-28T22:04:59+00:00
https://github.com/addpipe/simple-recorderjs-demo