Trim Unnecessary Files From Git History ✂️🗃️
Here's a common scenario, You have committed a file to your git repo and have also pushed to remote. The file wasn't supposed to be there, maybe it was something you forgot to mention in your`gitignore` or something that was supposed to be an environment variable or maybe it was a binary not related to the project at all ( Cat GIFs? 😉). This not only raises some security concerns but also drives the size of your repository up and simply deleting the file won't fix the problem. Here's how to fix it using a few commands: 1) Clone your repo and make sure all branches are up-to-date with remote. 2) Identity the filename and its path that you want to remove. 3) Then using git filter-branch remove the files from history. git filter-branch --tag-name-filter cat --index-filter \ "git rm -r --cached --ignore-unmatch filename" --prune-empty -f -- --all 4) Remove the files from the local repo. rm -rf .git/refs/original/ git reflog expire...