Jsinkler Dev

Oh-Git!

fire

When you just commited node_modules and your git is on fire!

What to do when you forget to add a .gitignore

So you upload your nodemodules/... Or for python users your virtualenv/, pycache... Whatever you upload, the case is that sometimes we add a ton of extra files, that we don't really want to store on github. Here's the steps to go through to get it all cleared up.

First step - add the .gitignore

At the top level of our repo let's make a .gitignore like we should have.

touch .gitignore

Either manually enter what you need to ignore or use something like gitignore.io.

If your project is in express you will want to at least add the following

node_modules/
DS_Store

If python you might want something like

venv/
__pycache__
.DS_Store

Second step - we are going to remove them from the cache

At the top level of our directory we run

git rm -r --cached .

This will remove all our files, which is ok, since we can add them back in in a moment.

git add .

We now add the files we want back in, but since our .gitignore is in place, git will now ignore the ones we don't want.

git commit -m "Removing all files in .gitignore"

Third step - Check out the git commits to see what happened :)

Happy coding,

James

Back to Home