When working on a Node.js project, your node_modules
folder can become quite large and should not be included in your Git repository. If your node_modules
folder is being tracked or pushed, it’s likely due to a missing or improperly configured .gitignore
file. Here’s how to fix it:
Steps to Ignore node_modules
in Git
- Create a
.gitignore
File (if it doesn’t exist)
Run the following command to create a.gitignore
file in your project directory:touch .gitignore
- Add
node_modules
to.gitignore
Open the.gitignore
file in a text editor and add the following line:node_modules/
- Remove
node_modules
from Git Tracking
Ifnode_modules
is already being tracked by Git, you need to remove it from the index:git rm -r --cached node_modules
- Commit Your Changes
Add the updated.gitignore
file to your repository and commit the changes:bashCopy codegit add .gitignore git commit -m "Added node_modules to .gitignore"
- Push Your Changes
Finally, push the updated repository to your remote:git push origin <your-branch-name>
From now on, the node_modules
folder will be ignored by Git, ensuring it doesn’t clutter your repository.