I'm trying to remove untracked directory git-blame-example . I've tried git clean -df
but it's not removing. Just to check i've also tried git clean -dfx
but got no solution.

- 5,443
- 3
- 27
- 39

- 185
- 1
- 4
- 15
3 Answers
It seems git-blame-example
project is also another git project inside git_test
.
You did not say what it says when you run command git clean -df
. I tried to replicate in my system and it says
Skipping repository git-blame-example/
So if you really want to delete it, then you have to add extra f
in the option.
You have to use this command to delete it
git clean -dff
You can find more about this in another answer.

- 2,054
- 2
- 22
- 26
-
1Thanks very much. You saved my life! – JohnWatsonDev Jan 30 '19 at 08:10
git reset --hard
Resets the index and working tree. Any changes to tracked files in the working tree since are discarded.
git clean -f -d
Remove untracked directories in addition to untracked files. In your case it looks like the untracked directory is managed by a different git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.
Also, If you don't want to remove files that are in .gitignore
, then do not provide the -x
flag.
Description:
Git Tips: Remove untracked files and directories from the working tree when switching branches or checking out different commits.
Explanation:
When switching branches or checking out another set of commits, you might want to only have the files and directories that are a part of that actual version. The commands shown above will accomplish this.
Be warned that any untracked files will be deleted, along with changes to tracked files. The two commands together reset the index and working tree, so ensure that any changes you don't want to lose were either committed to another branch or otherwise backed up somehow.
-f
--force
If the git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f or -n.

- 1,040
- 8
- 21
git-blame-example
in your case is a "submodule". To see its status:
cd git-blame-example
git status
Then you will see the untracked content in the submodule, which you can clean.

- 239,568
- 38
- 324
- 436
-
Yes, you're right. but can you tell me how can i delete this directory from git. because i've also tried to remove this `git rm -rf git-blame-example` – kvinbabbar May 06 '18 at 09:04
-
How to remove a submodule: https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule – John Zwinck May 06 '18 at 09:16