Skip to content

Instantly share code, notes, and snippets.

@olitreadwell
Last active April 9, 2023 19:49
Show Gist options
  • Save olitreadwell/30c8cb9fa724ac9dcf7e20bbfe723218 to your computer and use it in GitHub Desktop.
Save olitreadwell/30c8cb9fa724ac9dcf7e20bbfe723218 to your computer and use it in GitHub Desktop.
remove-node-modules-from-git-project

Remove node_modules from a Git Repo Project

The node_modules folder in a Node.js project contains a lot of files and directories that can be easily generated from the project's package.json file. Therefore, it's a good idea to exclude this folder from version control using a .gitignore file. Here are the steps to delete the node_modules folder, add it to .gitignore, commit the changes, push them to the remote repository, and then reinstall the dependencies using npm:

  1. Delete the node_modules folder:
rm -rf node_modules
  1. Create a .gitignore file in the root of your project if it doesn't exist already:
touch .gitignore
  1. Open the .gitignore file in your text editor and add the following line to it:
node_modules/
  1. Save and close the .gitignore file.

  2. Stage the changes to .gitignore and commit them:

git add .gitignore
git commit -m "Exclude node_modules folder from version control"
  1. Push the changes to the remote repository:
git push
  1. Reinstall the dependencies using npm:
npm install

This will recreate the node_modules folder and install the dependencies specified in your package.json file.

Resources

https://www.freecodecamp.org/news/what-are-node-modules/

https://www.atlassian.com/git/tutorials/saving-changes/gitignore

https://github.com/github/gitignore

https://www.youtube.com/watch?v=JciINzW-nfQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment