ONIZU

Removing a directory from the git repository after adding it to .gitignore

May 9, 2019 / Dushyant Basson

git

If a directory was added to .gitignore before pushing to the repository, it does not get pushed. But if the directory was already pushed, and later added to .gitignore, then to remove it from the repository:


git rm -r --cached dirToIgnore

git commit -m 'Removing the gitignored dir'

git push

The directory dirToIgnore should now be removed from the git repository.

Read on how to use Git to deploy a project on a remote server.