logo
podcast Podcast
get help Get Unstuck

Clean up dead git branch references automatically

When you merge a branch in GitHub, the reference to it is still in your local repo. How can you clean those up automatically?

Joel Clermont
Joel Clermont
2023-08-28

If you have a git branch locally on your machine, and it gets merged and deleted on the remote, the next time you git pull, it will not automatically clean it up. That remote branch will still appear as if it exists until you manually run git pull --prune.

After running this manually hundreds of times, I finally got annoyed enough to see if there is a way to do this automatically, and there is! Run git config fetch.prune true and now every git fetch or git pull will also clean up and prune those deleted branch references.

It's important to note this won't actually DELETE your local copy of the branch. It only deletes the remote reference to the deleted branch. But at least now you'll know an upstream branch was cleaned up, so you can decide if it's safe to delete on your end.

Here to help,

Joel

P.S. Laravel is pretty secure by default, but Aaron published a course to go even deeper on Laravel security.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.