Search code examples
gitgitignore

gitignore contents of subdirectories


I've have directory structure like :

a
|-- b
|   |-- qfq.txt
|   |-- ewfw.txt
|   | ...
|
|-- c
|   |-- wgfw.txt
|   |-- wjkh.txt
|   | ...
| ...

I need to gitignore all txt files in a/*/ . I tried /a/*/*.txt and /a/**/*.txt, but they don't work.

Please help. Thank you.



Updated : Solved

/a/**/*.txt works. Also, I came to know that git doesn't commit empty folders, not knowing which I thought the commands not working properly.

Thanks @JonathonReinhar, @phd, pankaj for quick response.


Solution

  • adding this in your .gitignore should do -

    $ cat .gitignore 
    a/**/*.txt
    

    Check this, I created the same directory and files structure

    $ find . -name *.txt 
    ./a/c/wjkh.txt
    ./a/c/wgfw.txt
    ./a/b/qfq.txt
    ./a/b/ewfw.txt
    

    but my "git status" is clean

    $ git status
    On branch master
    nothing to commit, working tree clean
    

    Make sure you first commit the .gitignore to the repo then only it will start ignoring files.

    Hope this helps