Problem
I do not know if you have faced this problem before, but if you are in a team maybe some of your colleagues or even you, had uploaded a file into the repository that should not be there, and then we found ourselves asking "What can we do to remove this file?".
First, we had to have put this file or file folder in our .gitignore file so that no one can upload it, not even by mistake. But don't worry we can fix it right away, just follow this simple steps.
Solution
1. Add the file or folder to ignore in your .gitignore file
(This is an example of a change in a .gitignore file)
## ADDING LOG FOLDER TO IGNORE AND ALL ITS FILES (Example)
log*
2. Make a commit with the change of your .gitignore file
git add .
git commit -m ".gitignore updated"
3. Remove the cache in your repository (this command is doing the job we wanted, it will remove all the files uploaded that should have been ignored)
git rm -r --cached .
4. Make a new commit to save the changes in your repository
git add .
git commit -m "Files removed from .gitignore"
And that is all, now you are able of updating any .gitignore file.
Top comments (2)
@jafetmeza Although you article is informative.
But if I may suggest, you can distribute the article in sub sections mentioning
Thank you for your suggestion, I will update the article.