Does git add -A respect .gitignore?

62 views Asked by At

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?

1

There are 1 answers

0
brianxk On BEST ANSWER

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.