Skip to content

Instantly share code, notes, and snippets.

@lmcneel
Last active April 21, 2024 19:39
Show Gist options
  • Save lmcneel/45594e550a3403d589bdcaad38138a83 to your computer and use it in GitHub Desktop.
Save lmcneel/45594e550a3403d589bdcaad38138a83 to your computer and use it in GitHub Desktop.
How to remove node_modules after they have been added to a repo

How to remove node_modules

Create a .gitignore file

  1. Check for an existing .gitignore file in the project directory
ls -a
  1. If your project directory has a .gitingore file - skip to step 3. Otherwise, continue with:

Create a .gitignore file in the git repository

touch .gitignore

Remove the node_modules directory

  1. Open up the .gitignore and add the following line to the file
**/node_modules
  1. Remove the node_modules folder from the git repository
git rm -r --cached node_modules

Commit All Changes

  1. Commit the git repository without the node_modules folder
git commit -m "Removed node_modules folder"
  1. Push the change to the remote repo
git push origin main
  1. Commit the .gitignore file
git add .gitignore
git commit -m "Updated the .gitignore file"
git push origin main
@jendahorak
Copy link

thanks, tried chatGPT,, but fucker got me sidetracked, this helped

@chimaris
Copy link

Thanks for this.

@aj910
Copy link

aj910 commented Sep 28, 2023

Thanks for this, very helpful!

@InjuSmol
Copy link

InjuSmol commented Nov 9, 2023

❤️

@rendi12345678
Copy link

thanks man, this is work in my machine :)

@saadjangdaa
Copy link

Thanks its working

@benjackson33
Copy link

Thanks for this, very helpful

@alperbayram
Copy link

thanks 💯

@joshuajcarter
Copy link

Just perfect! Thank you.

@ApurvaBasule
Copy link

👍

@davidMZL
Copy link

thanks !!! 😄

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