Git remove directory

Sometimes you want to remove a directory but keep it locally on your box. So you want to exclude it from the repository, but keep it locally.


We wanted to remove compiled VuePress Doc files from our Github repository. That can be done with a few easy steps. Steps I decided to write down so I can use them again in the future.


Exclude the directory in your .gitignore


That will exclude it if it is in Laravel resources. This you do so they do not get added again after you removed them from the repository.

Git Cache Directory Removal

Then you can remove the folder form the git cache so it will be removed from the repository, but keep your local copy. This can be done using:

git rm -r --cached myFolder 


Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.