Skip to content

Instantly share code, notes, and snippets.

@lmcneel
Last active November 5, 2025 11:41
Show Gist options
  • Select an option

  • Save lmcneel/45594e550a3403d589bdcaad38138a83 to your computer and use it in GitHub Desktop.

Select an option

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
@BekzodIsakov

Copy link
Copy Markdown

I got it. Thanks!

@gabrielfogaca

Copy link
Copy Markdown

Thanks!

@MPDADDY

MPDADDY commented Aug 1, 2023

Copy link
Copy Markdown

Thanks, that was helpful.

@JustCLE4R

Copy link
Copy Markdown

thanks thats very helpful, my brain ass just push everything without looking what i push until i push node_modules LOL

@thelittlemitak

Copy link
Copy Markdown

thanks thats very helpful, my brain ass just push everything without looking what i push until i push node_modules LOL
jijij I did the same. thanks a lot!

@DavidJRRJ

Copy link
Copy Markdown

Thanks!

@polooner

Copy link
Copy Markdown

omg timeless post already

@Salamandrachka

Copy link
Copy Markdown

you are the best! saved me a lot of time!!! thanks)))

@jendahorak

Copy link
Copy Markdown

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

@chimaris

Copy link
Copy Markdown

Thanks for this.

@aj910

aj910 commented Sep 28, 2023

Copy link
Copy Markdown

Thanks for this, very helpful!

@InjuSmol

InjuSmol commented Nov 9, 2023

Copy link
Copy Markdown

❤️

@rendivs925

Copy link
Copy Markdown

thanks man, this is work in my machine :)

@saadjangdaa

Copy link
Copy Markdown

Thanks its working

@benjackson33

Copy link
Copy Markdown

Thanks for this, very helpful

@alperbayram

Copy link
Copy Markdown

thanks 💯

@joshuajcarter

Copy link
Copy Markdown

Just perfect! Thank you.

@ApurvaBasule

Copy link
Copy Markdown

👍

@davidMZL

Copy link
Copy Markdown

thanks !!! 😄

@saharfallahi

Copy link
Copy Markdown

thanks, it's very helpful.

@suresh-ixe

Copy link
Copy Markdown

Thanks!

@NYOGamesCOM

Copy link
Copy Markdown

I just lost 2 weeks of updates by doing this, thanks

@lmcneel

lmcneel commented Jun 3, 2024

Copy link
Copy Markdown
Author

@NYOGamesCOM The ways that I know that updates could have been lost are:

  • Not entering the commands as written in the gist
  • Having updates in the node_modules folder. This is inadvisable as updating packages would have also resulted in the lost changes, and node_modules are not to be committed to git. The point of this gist is to remove the node_modules folder from git. It assumes this is the intended action, and these files have not been touched except through package management.

Can you provide more details? If there is an issue I'm missing, I certainly want to update the instructions.

Those changes may also be available in the git commit history. The above commands do not alter the commit history.

@Surjoyday

Copy link
Copy Markdown

Thanks, that was really helpful.

@MadeinPh1la

Copy link
Copy Markdown

Still helping in 2024. Thank you!

@imursugarmommy

Copy link
Copy Markdown

Thank you so much!

@ducgiang01

Copy link
Copy Markdown

Thank you so much!

@saifkp517

Copy link
Copy Markdown

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

lmao i laughed too hard at this

@karfong

karfong commented Jul 31, 2025

Copy link
Copy Markdown

Thank You, it help alot

@RiyaSharma028

Copy link
Copy Markdown

thanks

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