85

Possible Duplicate:
Ignoring directories in Git repos on Windows

My web app has the following directory layout:

myapp/
    .gitignore
    .git/
        ...

    static/
            mytest.txt
            fgs.ico
    ledgerware/
        static/
            mytest.txt
            fgs.ico
        ...

I'd like to edit existing myapp/.gitignore file so that when git push it ignores all files inside myapp/ledgerware/static folder, but NOT myapp/static folder. Can someone help me with this?

Community
  • 1
  • 1
synergetic
  • 7,756
  • 8
  • 65
  • 106

1 Answers1

101

Just make the line in .gitignore as specific as you want it to be:

ledgerware/static/*
FoolishSeth
  • 3,953
  • 2
  • 19
  • 28
  • 16
    If OP need to ignore the folder itself as well, the `*` can be removed from the end of the line. And alternatively, OP could also put a local `.gitignore` file in `ledgerware/` which ignores `static/*`. – m.brindley Feb 05 '13 at 05:46
  • 13
    If everything is ignored inside a folder then that folder is empty. Aren't empty folders ignored by git automatically? – Michael J. Calkins Dec 05 '13 at 15:38
  • 5
    @MichaelJ.Calkins yes they are, but you're talking about an egg popping out an egg here. git first has to ignore the contents of a folder before it can be seen as empty by git. the folder's probably not empty while running the project, probably a folder to hold environment specific files and working files or output, so we don't want to commit our output, we just want the folder – pythonian29033 Jul 20 '16 at 10:25
  • Does not work. The directory despite having contents, is not added at all, but is totally ignored (with the contents all being ignored). – Brian Knoblauch Sep 04 '21 at 20:40
  • @m.brindley : not true. I had to append the * to a folder in order to have the folder content excluded but the folder (and a file `.gitkeep`) included. git version 2.34.1.windows.1 – theking2 Jun 20 '22 at 09:39