Stop Git From Committing the node_modules Directory in a Node.js Application
When you create new commits and push them to a remote Git repository, how do you tell Git to ignore the
node_modules directory? And to not have its contents pushed to GitHub?
node_modules directory is usually way too large to store on GitHub and is installed after the repository is cloned via
You can do this using the
In the root location of your application directory, create a new
.gitignore file and add this line of code to it:
That will tell Git to ignore that entire directory when pushing updates to your remote Git repository on GitHub or GitLab.
.gitignore file should also include things like
.env files, any build files/directories, log files, test outputs, and more.
Thanks for reading and happy coding!