gitgitignore

Git does not delete a git repo which is in ignored directory


I have a .gitignore file which contains the target directory. And now I have realised that git that git will not delete a git repository which is in the target directory even if I do:

$ git clean -fdx
Skipping repository target/x

Does there exist a solution to handle that? Special configuration option? Cause I have given -f force etc. ?

Update:

I can create manually a repository in the target directory via the following manual steps:

maven-it-extension (issue-21)$ git st
On branch issue-21
Your branch is up to date with 'origin/issue-21'.

nothing to commit, working tree clean
maven-it-extension (issue-21)$ mkdir target/x
mkdir: target: No such file or directory
maven-it-extension (issue-21)$ mkdir -p target/x
maven-it-extension (issue-21)$ cd target/x/
x (issue-21)$ git init .
Initialized empty Git repository in /Users/khmarbaise/ws-git-apache/maven-it-extension/target/x/.git/
x (master #)$ cd ..
target (issue-21)$ cd ..
maven-it-extension (issue-21)$ git status
On branch issue-21
Your branch is up to date with 'origin/issue-21'.

nothing to commit, working tree clean
maven-it-extension (issue-21)$ git clean -fdx 
Skipping repository target/x
maven-it-extension (issue-21)$ 

Update

Using a supplemental -f is the solution which looks like this:

maven-it-extension (issue-21)$ git clean -f -fdx 
Removing target/

Solution

  • Try running git clean -f -f -x -d (or git clean -ffxd)

    Quoting the doc (and heavily hinted in the question suggested by @LasseVKarlsen) :

    -f, --force

    If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f or -i. Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second -f is given.