1

I am working on a node js project and I am creating a node module that for now want have it added to the project I am working on. So in my gitignore I put the following but it did not work

node_modules/*
!node_modules/zephyr-rest

The zephyr-rest is a directory, so I want just that directory and its files to be saved. I do not want any other sub directory under node_modules to be versioned. Thanks

jrock2004
  • 3,229
  • 5
  • 40
  • 73

1 Answers1

5

Try this, worked for me.

node_modules/*
!node_modules/zephyr-rest/

After git status it will show like this

Untracked files:
  (use "git add <file>..." to include in what will be committed)

  node_modules/

Don't worry because git status just tells the top-most untracked folder as untracked not every subfolder, so this tells there is an untracked folder node_modules. Doing git add node_modules should add just node_modules/zephyr-rest/

Mritunjay
  • 25,338
  • 7
  • 55
  • 68
  • Here is what git status shows me after the change On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: routes/index.js Untracked files: (use "git add ..." to include in what will be committed) node_modules/ no changes added to commit (use "git add" and/or "git commit -a") – jrock2004 Jul 16 '14 at 13:43
  • so it should be working. If you are getting confused it's showing `node_modules` try to add it will add just `zephyr-rest` folder. – Mritunjay Jul 16 '14 at 13:45