Skip to main content

Sync and cleanup

gji is not only for creating worktrees. The maintenance commands matter just as much once you have several branches in flight.

Sync the current worktree​

gji sync

This fetches and rebases the current worktree onto the configured default branch.

Sync every worktree​

gji sync --all

Use this when you have multiple active branches and want to bring them forward together.

Detached worktrees are skipped automatically because there is no branch to rebase cleanly.

Finish one worktree​

gji done feature/auth-refactor

This safely finishes the worktree and, when appropriate, its branch.

Bulk cleanup​

gji clean

Use clean when you want to prune multiple stale worktrees in one pass instead of removing them individually.

The interactive picker starts with the current repository. Press Tab to include linked worktrees from all registered repositories; each repository's primary worktree and the current worktree remain protected.

If a registered repository cannot be inspected, clean reports it instead of silently treating it as empty. When cleanup spans multiple repositories, the output includes one gji undo --id ... command per repository so the whole operation can be restored.

For stale-only cleanup:

gji clean --stale

--stale targets clean branch worktrees whose upstream is gone and whose changes are already merged into the configured or remote default branch, including squash- or rebase-merged changes.

Force options​

When you know you want non-interactive cleanup:

gji clean --stale --force
gji clean --force
gji done feature/auth-refactor --force

Force mode is useful for automation or when you have already reviewed the state and want to skip confirmation prompts.

What to check before cleanup​

  • Does the branch still contain work you need?
  • Is the worktree dirty or does it contain untracked files?
  • Is the branch merged already?
  • Do you want to keep the branch but remove only the worktree?

gji prompts for these cases interactively so you do not have to remember the right raw git worktree incantations.

gji remove and rm are deprecated compatibility commands. Use gji done for one worktree and gji clean for bulk cleanup.