The node_modules
directory is an integral part of any JS project. However, it makes sense
to exclude it from your git
commits. You can remove node_modules
from
the remote repository by adding it to the .gitignore
file.
When you’re starting a fresh JS project, then excluding node_modules
from git
is very easy.
Create a plain text file called .gitignore
(yes it starts with a dot) in the root
directory of your project and add a single line to it.
node_modules
Excluding node_modules that have already been committed
To exclude node_modules
after already having committed them, you should first launch
your terminal and clear git
including cached files and folders.
git rm -r --cached .
Then, go ahead and create a .gitignore
file with the node_modules
string in it.
And voilà! You’re ready to commit your changes without the node_modules
folder.
git add .
git commit -m "Removed node_modules folder and added it to .gitignore"
git push