1

my directory structure is like this:

roo
   |
   node_modules
         |
         packages
         |
           project1
                  |
                  lib
                  node_modules
           project2
                  | 
                   build
                   node_modules

I want to exclude lib, build or node_modules no matter where they are in the directory structure.

Here is my .gitignore

# dependencies
node_modules
/node_modules/

# testing
/coverage

# production
/build
/lib

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.tern-port

packages/*/lib/*
packages/*/dist/*

npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log

packages/*/node_modules
packages/*/lib
packages/*/build
dagda1
  • 26,856
  • 59
  • 237
  • 450

1 Answers1

1

Two options:

  1. Use an .ignore file, and add the following to skip lib and node_moduels (for example):

    *node_modules/ *lib/

  2. Use the command line option to ignore a directory, the "--ignore-dir." For example, if you want to ignore node_modules and lib, you'd use this:

    ag --ignore-dir lib --ignore-dir node_modules value

Note: I tested this with your exact directory structure.

gregory
  • 10,969
  • 2
  • 30
  • 42