Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

.gitignore for node_modules? #25

Closed
erelsgl opened this issue Jun 12, 2013 · 12 comments · Fixed by #32
Closed

.gitignore for node_modules? #25

erelsgl opened this issue Jun 12, 2013 · 12 comments · Fixed by #32

Comments

@erelsgl
Copy link

erelsgl commented Jun 12, 2013

When I fork this repo, and do "npm install", the folder is filled with node_modules, and since there is no .gitignore, git tries to commit them...

From what I read, there are two options for handling node_modules in git projects:

A. Keep all the node_modules in the git repository, together with my project, or:

B. Don't keep any node_modules in the git repository, and have a ".gitignore" file that contains "node_modules".

However, here, there are no node_modules, but also no .gitignore file...

I am not an expert, so maybe it's my mistake.

@francescortiz
Copy link

You can create your own .gitignore which ignores itself.

Create a .gitignore with this two records:

.gitignore
node_modules

@erelsgl
Copy link
Author

erelsgl commented Jun 21, 2013

Thanks, I think it would be easier for new users and contributors to have this .gitignore bundled with the code, so that they don't have to add it themselves.

vishbin pushed a commit to vishbin/brain that referenced this issue Sep 3, 2014
Closes harthur#25
* Ignores the node_modules directory because it's not needed in the repository.
* Ignores the DS_STORE file on Mac because it's pointless committing that every time.
* Ignores npm log file because it's unnecessary to store that in the repository.
@umerjamil16
Copy link

You can create your own .gitignore file and add the folders/file names you want to exclude from your git repositories in production.

@amarkantk14
Copy link

To create .gitignore file use touch command

user-name$ touch .gitignore
then open .gitignore file and add /node_modules

.gitignore
/node_modules

it will work.

@DMW007
Copy link

DMW007 commented Jan 29, 2018

Seems not to work with subfolders. I have the following directory structure:

<git-root>
-- server
---- node_modules

By simply adding node_modules to .gitignore, a lot of files in server/node_modules are marked as unstaged. Only excluding the hole path server/node_modules/ works as expected.

@rrajvanshi1947
Copy link

In your root folder within the .gitignore file, you need to write *node_modules to ignore the node_modules folder under any sub folder.

@Macil
Copy link

Macil commented Nov 21, 2018

@rrajvanshi1947 Just "node_modules" without a / at the start will do that too. (.gitignore ignores the listed files in any directory, unless they start with /, in which case the line is expected to be the relative path to a file.)

@dmoraroca
Copy link

To create .gitignore file use touch command

user-name$ touch .gitignore
then open .gitignore file and add /node_modules

.gitignore
/node_modules

it will work.

For me, it worked

@Mstarr85
Copy link

Thank you!

@MelanieRogoff
Copy link

I saw a great answer on StackOverflow by a fellow programmer (https://stackoverflow.com/users/2854041/andrew-schreiber). He wrote: touch .gitignore && echo "node_modules/" >> .gitignore && git rm -r --cached node_modules ; git status
It works perfectly (I'm using an OS).

@AlongTheDeveloper
Copy link

hello

@DavidCortes13
Copy link

Cual debería ser el modo correcto de guardar node_modules en mi proyecto, ¿Dentro o fuera del .git ignore?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.