How to clean up your local git branches
What happens to all of those local branches after the pull request has been merged and deleted on Github?
Read more [tomschlick.com]
What happens to all of those local branches after the pull request has been merged and deleted on Github?
Read more [tomschlick.com]
Today I accidentally committed a multi GB file to the git repo of the project I was working on and pushed it. Damn! Because of that big file cloning the repo again would take a long long time. Removing the file locally and pushing again would not solve the problem as that big file is in Git's history.
So I took a few moments to Google around and learned that that there actually is a git command that can rewrite history: filter-branch. This is how I removed that big file from history:
git filter-branch --tree-filter 'rm path/to/your/bigfile' HEAD
git push origin master --force
Both commands took a while to complete, but after that I had a light repo again.
If you need to do this, be sure to keep a copy of your repo around in case something goes wrong.
Here's an old, but still seemingly still correct blogpost by Dalibor Nasevic with some more info on the subject.
Few weeks ago I froze gems on my blog and ended up with a very big repository. So, I wanted to clean up the mess and remove permanently gems folder from the repository. git rm wasn't doing the job well, it only removes the folder from the working tree and the repository still contains the objects of this folder. After a quick search, I found that git-filter-branch was the command I was looking for.
https://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"Freek’s newsletter is one of the best ways to stay updated with the Laravel and PHP ecosystem. It consistently highlights useful packages, tools, and ideas from the community, especially the amazing work coming from Spatie. As a Laravel developer building SaaS and web platforms, I find it extremely helpful to discover practical tools and insights that improve my development workflow."
Most databases will contain some records that must be cleaned up. The reasons why a record can become unneeded are diverse: maybe it's a temporary record that was only needed for a little while if you're logging stuff to a table, a record may become too old to be of interest anymore ... To help a…