Clean up dead git branch references automatically


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.

Want a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.