99

What I did:

I think there were some weird configurations from the github gui that caused this issue and prevented me from being able to easily use git from command line or even git-bash.

I ended up just uninstalling github and git then reinstalling just git for windows. I now have everything running off the command line(except ssh which I run from git-bash). Much easier and more reliable that the github gui.

Thanks to mu 無 for taking the time to try to figure this out. I didn't end up using his answer, but if I hadn't needed to do a reinstall of git it would have been what I needed to do.


I am using the github gui on my local machine. I just noticed that a commit I was about to make was going to update all of my recently update node modules. I set up my .gitignore to ignore the entire node_modules/ directory.

I'm not sure what to do about this. All the file types I included in .gitignore were ignored. It's just the directories that it seems to ignore.

Here is my .gitignore file:

################# ## Sublime Text ################# *.sublime-project *.sublime-workspace ################# ## Images ################# *.jpg *.jpeg *.png *.gif *.psd *.ai ################# ## Windows detritus ################# # Windows image file caches Thumbs.db ehthumbs.db # Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Mac crap .DS_Store ################# ## Directories ################# dev/ cms/core/config/ node_modules/ 
10
  • what is the output of git status? Add that to the question... Commented Apr 7, 2014 at 22:57
  • 1
    I don't know anything about that Commented Apr 7, 2014 at 22:58
  • Go to your terminal, and run git status in the repository. Whatever is the output, put them here. Commented Apr 7, 2014 at 22:59
  • I am on a windows machine. So terminal git commands don't work. 'git' is not recognized as an internal or external command, operable program or batch file. Commented Apr 7, 2014 at 23:01
  • 1
    Look this: making git forget about a file that was tracked but is now in gitignore | StackOverflow Commented Aug 14, 2016 at 13:55

10 Answers 10

331

Since the node_modules directory is already tracked as part of the repository, the .gitignore rule will not apply to it.

You need to untrack the directory from git using

git rm -r --cached node_modules git commit -m "removing node_modules" 

You can run the above 2 in git-bash.

After this, the .gitignore rule will ignore the directory away.

Note that this will remove the directory node_modules from your other repos once you pull the changes in. Only the original repo where you made that commit will still have the node_modules folder there.

Sign up to request clarification or add additional context in comments.

16 Comments

That is not a typo. The directory created by node is node_modules/
the ignore rule is node_modules, and in your question, at the beginning it is node_module.
How do I untrack without command line? Or how do I access git in command line on a windows machine and no bash?
go to git-bash. Git for windows comes with its own git-bash. How do you otherwise commit from windows?
I commit with the github gui. That's all I've ever used in windows. On linux I can just access git from the command line.
|
34

Similar to Zach, I also used echo "node_modules/" >> .gitignore.

The problem was it had created the file with encoding UCS-2 LE BOM. Using notepad++ I changed the encoding to UTF-8 and voila - node_modules is now ignored.

enter image description here

2 Comments

This answer should have much more up votes as the problem and solution are really surprising. Thank you!
I did exactly this, fml. Just deleted and re-created using VS Studio. Thanks @Scotty.NET
21

If the files are already tracked the .gitignore file will not override this. You will need to use git rm --cached <files>

See the full details on git rm at https://www.kernel.org/pub/software/scm/git/docs/git-rm.html I ran into this once or twice myself early on with git and it was not quite what I expected either.

1 Comment

This is more comprehensive answer to the title in question if we ignore the typo problems in the OP's question. Useful for people arriving w/ search.
4

If you work with node projects, I like this .gitignore:

# See http://help.github.com/ignore-files/ for more about ignoring files. # dependencies node_modules # testing coverage # production build # misc .DS_Store .env npm-debug.log 

Comments

3

I had this problem. Somehow when I generated the file (using echo "node_modules" > .gitignore) it had inserted a garbage character at the beginning of the file (I blame powershell).

So, if you run into this problem try deleting your .gitignore and starting over.

1 Comment

Seems to be a powershell issue, since same thing happened here.
0

None of the solutions above worked for me and I don't know why

Eventually what I did was:

  1. Duplicated to project folder in order to don't work with the main one
  2. Then I removed .git & .gitignore file (CMD+SHIFT+DOT shows hidden files)
  3. Added .gitignore file with touch .gitignore at root and added node_modules
  4. Initialized git again with git init
  5. Added remote again with git remote add origin your_repo
  6. git add .
  7. git commit -m 'added ignore file'
  8. git push -u origin master

And continue working with this new directory. Please note that it was a solution for me because it was my first commit.

Comments

0

Well what works for me was add "node_modules" to .gitignore

backend\node_modules frontend\your_proyect\node_modules node_modules 

Comments

0

Just remove the initial git configuration from your folder by rm -rf .git. Use the created .gitignore file and add all the file you want to add. Then reinitialize the git configuration in your folder with git init. This will solve your problem.

Comments

-1

try this command, it will resolve your issue:

git config core.ignorecase true 

Comments

-1

I haven't seen this posted anywhere, as perhaps it should be obvious, until I forgot, but adding a comment to the end of a gitignore line is NOT actually a comment! Comments on their own line!

# .gitignore (this is a comment) my_bad_dir/ # This is not a comment, and my_bad_dir/ won't be ignored 
~$ man gitignore | grep comment • A line starting with # serves as a comment. 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.