Ignoring a directory chain in git?

I need to ignore the following.

In paths like /a/b/c/d/e/f/g, I need to ignore /d/e/f/g. I also need to be able to ignore every place /d/e/f/g appears beneath a. I tried d/e/f/g, but that did not work. Thoughts?

  • How to keep git from changing file ownership
  • File not shown in git diff after a git add. How do I know it will be committed?
  • Error cannot stat upon git pull
  • Is there a command which will print the path of the file in the repo-browser in the command line?
  • Git porcelain command to revert a single file to its HEAD state but keep its staged state?
  • Remove file from commit
  • How to effectively organize scripts so they can be put under version control?
  • How to tell ANT-exec, the location of git executable
  • “git show” does not return same result as “git diff”
  • git svn ignore paths use ignore file
  • Why do I have to stash / commit my changes before switching branches?
  • How to keep git from tracking all files that end with a “~”?
  • 2 Solutions collect form web for “Ignoring a directory chain in git?”





    Interesting requirement. I’m curious what your use case actually is.

    The way you should do something like this is a separate .gitignore in the parent directory of each sub-tree you need to exclude (git reads all the .gitignore files on its way down the tree).

    If you really want a single .gitignore file… Well, I haven’t tried this, but going by the gitignore doc, it’s mostly a typical shell glob, so what might work is something like:


    … repeating with an ever-increasing number of asterisks out to the deepest you expect it to reasonably go.

    I imagine there will be a performance penalty here, but I don’t know how serious. Probably not noticeable for most repos on any system built in the last 5-10 years.

    Git Baby is a git and github fan, let's start git clone.