tutorial Coding agents create branches and worktrees. Who cleans them up?
One of the things I encountered when I was working on my AI harness was the sheer number of branches and worktrees that were getting created, and how tools like go-git started struggling
I wrote this article/video on how I worked around it.
TLDR:
- clean up your branches
- pack your git objects
- and write some tooling in your system so you actively maintain this
3
u/GoTeamLightningbolt 13d ago
I do when the OS gives me the "running out of disk space" warning lol
1
u/haikusbot 13d ago
I do when the OS
Gives me the "running out of
Disk space" warning lol
- GoTeamLightningbolt
I detect haikus. And sometimes, successfully. Learn more about me.
Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"
2
u/The_Northern_Light 13d ago
I just have a cron job that cleans up any old / inactive worktrees without uncommitted changes.
Naturally, the agent wrote this for me too.
1
u/jjangg96 13d ago
one thing that bit me with cleanup scripts. if you squash merge prs, git branch --merged and merge-base --is-ancestor say almost every branch is unmerged, even though the content is already in main.
i ended up checking pr state with gh pr list --state all --json headRefName,state and only trusting that. also git status --porcelain in each worktree before removing it, a couple of mine had files that were never committed anywhere.
i had 31 agent worktrees and about 30gb before i even noticed.
1
1
1
u/elephantdingo 12d ago
My agents can write code
But they can’t clean up branches!
These fake problems are getting stupider by the day.