It’s worth noting that the first approach doesn’t completely remove the offending file from the remote repository. Checking out a commit between the times it was added and removed, the file will still be available. It might be important depending on the reason why you wanted to remove it. Two typical cases where it won’t be enough to delete the file in a new commit:
very large file that should not be committed and will unnecessarily blow up the repository size;
sensitive file containing passwords or API tokens.
In this case, and if the file has been there for a few commits, you will probably need to use git filter-branch, which is not for the faint of heart, or the easier to use BFG Repo-Cleaner.
Japanese translator turned software engineer. I work mostly with Ruby and Rails. Currently a post-bacc computer science student @ University of Colorado.
Location
Connecticut
Education
University of Colorado, Ohio State University, IUC (for Japanese)
Thanks for pointing that out! Definitely want to be careful with sensitive data. I added a note and link to your comment in the article so everyone will see it.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good post, thank you.
It’s worth noting that the first approach doesn’t completely remove the offending file from the remote repository. Checking out a commit between the times it was added and removed, the file will still be available. It might be important depending on the reason why you wanted to remove it. Two typical cases where it won’t be enough to delete the file in a new commit:
In this case, and if the file has been there for a few commits, you will probably need to use
git filter-branch
, which is not for the faint of heart, or the easier to use BFG Repo-Cleaner.Thanks for pointing that out! Definitely want to be careful with sensitive data. I added a note and link to your comment in the article so everyone will see it.