Problem Statement

The node_modules directory contains all your project’s dependencies. Since these files can be large and are recreated using package.json, it’s best practice to exclude them from version control.

Solution

To ignore the node_modules folder from being tracked by Git

Open (or create) a .gitignore file in the root of your project.

Add the following line

node_modules/

Save the file.

If node_modules was already being tracked, remove it using

git rm -r –cached node_modules

Then commit the changes

git commit -m “Ignore node_modules folder”

Also Read:

Push to your repository

git push origin main

Conclusion

Using a .gitignore file helps maintain a clean repository and reduces unnecessary data. Excluding node_modules also ensures faster cloning and a smaller repo size.