Search code examples
gitversion-controlgitignoregit-add

Does git add -A respect .gitignore?


I have several target subdirectories in my project that I do not want to track. So I removed them all with:

find . -type d -name 'target' -print0 | xargs -0 git rm --cached -r --

I also added ./*/target/ to my .gitignore file.

I then ran git add -A and it appears all of my target subdirectories were tracked and I had to remove them again.

Does git add -A simply not respect .gitignore? Will I have to run git add with a different option?


Solution

  • Turns out I had the incorrect format in my .gitignore file.

    I replaced

    ./*/target/
    

    with

    */target/**
    

    */target/** will recursively ignore all the contents of all */target subdirectories.