How do you delete untracked local files from your current working tree?
I like to use git stash
command, later you can get stashed files and changes.
git clean
is also a good option but totally depends on your requirement.
here is the explanation of git stash and git clean,7.3 Git Tools - Stashing and Cleaning
Note: First navigate to the directory and checkout the branch you want to clean.
-i
interactive mode and it will tell you what will be removed and you can choose an action from the list.
To clean files only [Folders will not be listed and will not be cleaned]:
$ git clean -i
To clean files and folders:
$ git clean -d -i
-d
including directories.
If you choose c
from the list. The files/folders will be deleted that are not tracked and will also remove files/folders that you mess-up.*
For instance: If you restructure the folder in your remote and pull the changes to your local computer. files/folders that are created by others initially will be in past folder and in the new one that you restructure.
protected by Jorgesys Jan 13 '14 at 23:49
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
git clean
has now an interactive mode! See my answer to this other question: git 1.8.4+ – VonC Jul 23 '13 at 6:00git clean
or some variation in the answers below, including the interactive version to delete just selective files, but interactive mode can be tedious. Whatever you do, make sure you understand whatgit clean
will delete or use--dry-run
to have it tell you without deleting anything. – LightCC Sep 2 '17 at 6:15rm files-to-be-deleted
– mhatch Mar 14 '18 at 20:48