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:

  • Connecting to gitosis server through an SSH tunnel
  • How to monitor a git repository for changes?
  • Using Maven Archetype Generate in the same Directory
  • Git post-rewrite not executed
  • Git cat staged file to stdout
  • Old remote alias still visible in git logs and gitk, how to delete?
  • # 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?

  • Django + twitter bootstrap + github what's the most elegant way to do this?
  • git rebase “--preserve-merges --onto” doesn't preserve merges
  • git merge says Already up-to-date but there's a committed difference in the branches
  • using git-flow with multiple git repositories per project/app?
  • TFS 2017 Build Automatically kicks off and keeps failing
  • Moving a Git install on Linux
  • 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.