Removing Node Modules from GitHub with .gitignore
It's common to have large dependencies like node_modules that you don't want to include in your GitHub repository. This clutters up the repo and makes fetching and cloning slower. Luckily, Git has a handy feature called .gitignore that allows you to specify files and folders you want Git to ignore.
The steps to remove node_modules or any other folder from GitHub are simple:
Create a .gitignore file in your repo's root directory if one doesn't already exist.
Add
node_modules/
as a new line in .gitignore. You can also add other files and folders you want ignored here.
Don't forget to save the .gitignore file after adding entries!
Make sure the paths in .gitignore are correct for the files/folders you want to ignore. For example, node_modules/
will ignore the node_modules folder in the repo's root directory.
- Stage the changes to .gitignore for commit:
git add .gitignore
- Commit the changes:
git commit -m "Ignore node_modules"
- Delete the node_modules folder from the repository:
git rm -r --cached node_modules
- Commit the removal:
git commit -m "Remove node_modules"
- Push the changes to GitHub:
git push origin master
That's it! Node modules or any other specified folders/files will now be ignored. The next time you fetch or clone the repo, they won't be included. Using .gitignore helps keep your repositories lean and fast!
Subscribe to my newsletter
Read articles from Raj Maurya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by