Skip to content

Recover work from a worktree

From inside the worktree:

Terminal window
graft status agent/my-branch

It lists uncommitted paths and local commits no branch on GitHub contains, checked through the API. nothing local that GitHub does not have means it is safe to remove.

If the work is merged, graft worktree done agent/my-branch rewinds the branch so worktree tools stop counting published commits as lost. It exits 1, changing nothing, if anything is local only. With graft’s hooks wired, ExitWorktree remove runs it for you and is refused when something is local only.

cambium removes a worker’s worktree only when GitHub holds everything in it. Otherwise it keeps it and logs a warning with the reason in ~/.cambium/logs/cambium.log.

To see what the periodic sweep would do with every worktree:

Terminal window
cambium gc --dry-run --repo owner/name

A worktree idle for gc.staleDays (14 by default) with unpublished work is archived, then removed:

~/.cambium/gc/<owner>__<name>/<dir>-<stamp>/
commits.bundle local commits not on origin/<base>
changes.patch uncommitted changes
untracked/ untracked files
worktree.json where it was and which branch
  1. Restore the commits into your clone:

    Terminal window
    git fetch ~/.cambium/gc/owner__name/<dir>-<stamp>/commits.bundle HEAD:recovered
  2. Check out recovered, then apply the rest:

    Terminal window
    git apply ~/.cambium/gc/owner__name/<dir>-<stamp>/changes.patch
    cp -R ~/.cambium/gc/owner__name/<dir>-<stamp>/untracked/. .

To change when the sweep runs or archives, set gc.everyMinutes, gc.graceMinutes and gc.staleDays: cambium configuration.