Remove files from your remote git repository
27 May 2020Oops! I committed files (that I don’t want to be tracked) to the remote again.
My most frequent oversight when dealing with git is creating a commit that includes files that I do not wish to be tracked, because I forgot to update the .gitignore
file.
If you have already pushed your commit, then creating a new commit with an updated .gitignore
won’t delete these files from the remote (it will just keep them from being updated).
If you’re as clumsy as I am, then here’s what to do:
- Configure your
.gitignore
correctly by adding the files or directories you wish to ignore. - Run the following commands at the base of your local repository:
git rm -r --cached . git add . git commit -m "removed unnecessary files from git" git push origin
The files shouldn’t appear in the remote anymore.