Why does git clean -dX not remove my ignored directory?

I would like git to clean up all untracked files that I have ignored.

I thought that git clean -dX was the obvious solution, but it does nothing:

  • Git is not using the first editor in my $PATH
  • git - how to handle confilicts
  • Aptana Studio freezes when I try to do a push to my repository
  • linking git and github repositories
  • How do I 'overwrite', rather than 'merge', a branch on another branch in Git?
  • How is a pathspec supposed to work?
  • # Set up test directory
    mkdir git-test && cd git-test
    git init && touch x && git add x && git commit -m Initial
    
    mkdir -p folder1/folder2/
    touch    folder1/folder2/file
    
    echo "folder2/" >> .gitignore
    
    git clean -fdX     # Does nothing
    

    Why is it not removing folder1/folder2/?

    The docs say that

    • **/foo matches file or directory foo anywhere, the same as pattern foo

    so my folder2/ pattern does match /folder1/folder2/ and -X should clean it.

    What’s going on?

  • Git seems to store the whole file instead of diff, how to avoid that?
  • Git cherry pick commit from branch A to B
  • Do the file dates for bare git repositories represent the repository creation date?
  • How to squash a commit made in the GitHub website?
  • Git commit with no email
  • EGit and Stash with Eclipse - SSL hostname verification
  • One Solution collect form web for “Why does git clean -dX not remove my ignored directory?”

    What version of Git are you using? You may have run into this bug: Bug: git ls-files and ignored directories.

    This bug was fixed in v1.7.11.2. From the release notes:

    • git ls-files --exclude=t -i” did not consider anything under t/ as excluded, as it did not pay attention to exclusion of leading paths while walking the index. Other two users of excluded() are also updated.
    Git Baby is a git and github fan, let's start git clone.