Skip to main content

git - delete a folder from the repository after adding it to .gitignore

  • Blog
  • 0 Kommentare

Using .gitignore you can specify files and folders that should not be uploaded to the git repository.
But sometimes it happens that you upload / push all files to the git repo first and then realize that some of the folders should not be in the repo.
First you put this folder in the .gitignore and then you can use the following command to delete the folder from the repo. This will keep the folder on your machine and only delete it from the git repo.

git rm -r --cached my-folder
git commit -m 'Delete the now ignored folder "my-folder"'
git push origin master

All new changes in the folder will be ignored by git from now on. The next time you staging and push, the folder will no longer be present in the new git push.

Have fun!

By submitting your data, you agree that all entered data may be saved and displayed as a comment.

🤖 Cookies

We use cookies to improve your experience. Find out more in our privacy page.