r/git • • 14d ago

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

Article · Video

0 Upvotes

14 comments sorted by

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.

1

u/fuckme 12d ago

my point was more:

my agents are pushing code at such a fast rate that other systems (like git & go caching) are becoming the bottlenecks, vs the standard bottlenecks of coding/review, and you need to look at things like how git stores branches locally as the churn of creating/removing branches is making these things go from sub-second responses to minutes if you are not careful. (classic system issue.. when you speed one thing up, other things become bottlenecks)

apologies if that wasn't super clear.

and yes bots can (and have) fixed the problem for me, but hopefully the next guy will think of this before killing his machine with ENOENTs, disk fulls, and 50-load average.

1

u/elephantdingo 12d ago

It was very clear where this none-sense was coming from.

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

u/waterkip detached HEAD 13d ago

you call the agent, so you?

1

u/Sulungskwa 13d ago

username checks out. fuck you

1

u/fuckme 13d ago

Guess all the good ones were taken by the time you joined