Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Why does Git automatically ignore most Node files?

Why does Git automatically ignore most Node files?

Problem

I'm new at Node.js & NPM, and I'm experimenting by writing a website & adding it on Git (it's public, but only because I don't want to pay for private hosting). When I push the files to Github, Git automatically ignores pretty much every file related to Node, and I can't figure out why. Specifically, it seems to be ignoring all node_modules folders, Gruntfile.jses, and package.jsons. Is this because of Git or Node, or is it a dummy move somewhere on my part?

When I do git add -A, git add . or git add -u, all of which are supposed to include all added & deleted files (I think), and then use git commit or git commit -a I get something like this:

$ git commit -m "hopefully added all files"
On branch dev
Your branch is up-to-date with 'origin/dev'.

Untracked files:
        .jshintrc
        app/
        libs/Gruntfile.js
        libs/node_modules/.bin/_mocha
        libs/node_modules/.bin/_mocha.cmd
        libs/node_modules/.bin/mocha
        etc.

nothing added to commit but untracked files present

I tried searching for .gitignore anywhere in the root folder, but all I could find was a gitignore file in my Bootstrap folder (speaking of, why is that there?), but if I'm correct, that shouldn't affect folders above it? It had rules for node_modules, but not Gruntfile.js or package.json, and when I commented all rules on it the files were still ignored.

This is a submodule, so it uses the .git folder of the parent project. That parent project has nothing but comments in its .git/info/exclude, and also has no .gitignore. No other submodules have a .gitignore, either.

So why is this happening?

EDIT: git cherry & git diff both show nothing. git status shows:

$ git status
On branch dev
Your branch is up-to-date with 'origin/dev'.

Untracked files:
  (use "git add ..." to include in what wi

        libs/Gruntfile.js
        libs/node_modules/.bin/_mocha
        libs/node_modules/.bin/_mocha.cmd
        libs/node_modules/.bin/mocha
        libs/node_modules/.bin/mocha.cmd
        libs/node_modules/grunt-contrib-compass/
        etc.

nothing added to commit but untracked files present (use "git add" to track)

EDIT 2: This website is a submodule, but I have never used .gitignore or .git/info/exclude on the superproject or any other submodules. Nevertheless, could this have anything to do with the problem?

EDIT 3: As I said, git add -A, git add . & git add -u never add anything from node files or folders, but adding individual files & folders does. This makes it even weirder.

Problem courtesy of: trysis

Solution

If I understand it correctly, you have your project git repo that contains submodule repo in it. Can you please try this workflow?

  1. In some folder clone your submodule-repo
  2. In the same folder clone you project-repo and run
  3. cd project-repo
  4. git submodule init
  5. git submodule update
  6. cd ../submodule-repo
  7. Make changes and git commit -a; git push
  8. cd ../project-repo/submoduleDir
  9. git pull

Now, you should have the parent repo pointing to the new submodule revision and when you cd to the project-repo you can commit this change (project-repo pointing to the latest submodule-repo revision).

More on this topic can be found here:
* http://git-scm.com/docs/git-submodule
* http://joncairns.com/2011/10/how-to-use-git-submodules/

Hope it helps.

Solution courtesy of: Petr Volny

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Why does Git automatically ignore most Node files?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×