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.


This content originally appeared on David Walsh Blog and was authored by David Walsh

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.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2020-11-19T02:05:27+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 ,<https://www.scien.cx/2020/11/19/git-remove-untracked-files/>
VANCOUVER
David Walsh | Sciencx - » git: Remove Untracked Files. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/11/19/git-remove-untracked-files/
CHICAGO
" » git: Remove Untracked Files." David Walsh | Sciencx - Accessed . 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: ]
rf:citation
» git: Remove Untracked Files | David Walsh | Sciencx | https://www.scien.cx/2020/11/19/git-remove-untracked-files/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.