Remove Already Tracked Items from Git

After wrestling with a .NET app that wasn’t excluding the “packages” directory from the repo, I realized I had missed a crucial and obvious step… I forgot to commit the change to finalize the removal. Talk about one of those “you forgot a comma” moments…

If you find yourself in the same boat - here is how you do it.

To remove the directory:

git rm -cache -r directory/path/

This will recurse through the directory and pull all of its contents out of the history.

To finalize this, ensure that the directory is listed in your .gitignore file and commit the change:

git commit -m "Removed directory from tracking and added to .gitignore"

And that’s it!


Curtis Rissi

Solutions Architect and Full Stack Engineer by day and mad scientist by night. I specialize in making the impossible possible through code and technology. I also make some crazy good Korean BBQ. You know you want to try it.

Disclaimer: I work for AWS, but unless otherwise stated, the words and thoughts expressed in this blog are my own.

comments powered by Disqus