How to remove folders and files from git?

Viewed 58

I have some folders which was included in git commits in the past and now I would like to remove it from git.

So I have added the folder in .gitignore. But if I try to pull changes from server it throws me an error:

Pull failed. Some untracked working tree files would be overwritten by Pull. Please move or remove them before you can Pull.

In .gitignore is the line

/storage 

which should ignore everything what is in the storage directory. So why the pull has problem with file in storage/logs/20201455.log file?

2 Answers

Adding on to what biomiker mentioned, you can also do this:

git rm -r --cached storage

This will only remove it from the repository and keep the files, keep in mind you will have to add ./storage to your .gitignore file to make sure it doesn't get added again to the repo.

If the storage directory is already checked in to your repository you need to remove it:

git rm -r storage
git commit -m "Removed storage"

BUT this will also remove the contents of your storage directory, so move it somewhere safe first.

mv storage storage_orig
git rm -r storage
git commit -m "Removed storage"
mv storage_orig storage
Related