Remove Files/Folders from Git

bmckay959 Avatar

Ever forget to add a .gitignore to your project before making your first commit? Wonder why git is taking forever to upload to GitHub? By accident, I uploaded all my node_modules folder, of which, 1 file was over 70MB!

I wanted to get rid of my node_modules folder, so here is what you should do.

First, create a .gitignore file with at least the following contents. This will prevent the node_modules from being included in the future.


Next, we are going to remove the node_modules from the git index by doing this in the command line

git rm -r --cached node_modules

Now, we can run our normal flow of adding all of our changes and commit.

git add .
git commit -m "I made a whoopsie"
git push

And that’s it! You should see the node_modules removed from your git repository. You can change “node_modules” above to remove any files or folders from git.

Leave a Reply

Blog at

%d bloggers like this: