delete¶
git city delete removes a branch without merging it. Use it when a feature is a dead end — an experiment you are abandoning, a branch you already merged some other way, or work you no longer want in your stack.
Deleting is non-destructive in the ways that matter: any child branches are re-homed onto the deleted branch's parent so your stack stays connected, and the operation is fully reversible with undo because the commits survive in Git's reflog.
With no branch argument, git city delete operates on the current branch.
Asks before it deletes
Because delete removes the branch locally and on the remote, it prints the plan and asks for confirmation first. Pass --yes (or -y) to skip the prompt. Running non-interactively (a script or CI) without --yes is refused rather than assumed — so a destructive command never runs unattended by accident.
What it does¶
When you delete a feature branch, git-city:
- Re-homes its children — every branch whose parent was the deleted branch is reparented onto the deleted branch's parent (or the trunk, if it had none). Your stack closes the gap rather than breaking apart.
- Removes it locally — the local branch ref is deleted.
- Removes it on the remote — if the branch was tracked, the corresponding remote branch is deleted too.
The commits that were on the branch are not merged anywhere. They are no longer reachable from any branch, but they remain in the reflog, which is what makes undo able to bring the branch back.
Children move, commits do not
Re-homing is lineage metadata only — it records each child's new parent. The children's commits do not move during delete. The next sync rebases each re-homed child onto its new parent.
Example¶
Given this stack, where experiment is being abandoned but has a child follow-up:
Delete it:
follow-up is re-homed onto main, and experiment is removed locally and on the remote:
Run a sync afterwards to rebase follow-up onto its new parent.
Preview with --dry-run¶
Every mutating command accepts --dry-run, which prints the exact ordered git commands it would run and executes nothing:
→ Dry-run and reversible operations
delete vs. land¶
delete and land both end with the branch removed and its children re-homed, but they are opposites in intent:
delete |
land | |
|---|---|---|
| Branch's commits | Discarded (kept only in reflog) | Merged into the parent (fast-forward) |
| Parent branch | Unchanged | Fast-forwarded to the feature's tip |
| Use when | The work is abandoned | The work is finished and you want it |
| Refuses if | Trunk / dirty tree | Feature is behind its parent (sync first) |
In short: use land to keep the work, use delete to throw it away.
→ land
Undo¶
delete is reversible. undo restores the branch — including a remote branch git-city deleted — because the commits are still in the reflog:
Undo is single-level: it reverses only the last git-city command, and the run-state is overwritten by each new command, so undo a delete before running anything else.
Undo refuses rather than destroy
Undo will not run on a dirty working tree, and it will not delete a branch that carries commits living on no other branch. If you need to abandon work, delete is the command — undo is for taking it back, not for cleanup.
→ Recovery: undo, continue, abort
Errors¶
Like all commit-moving commands, delete refuses to run on a dirty working tree — commit or stash your changes first. It also will not delete a trunk (the configured main or any perennial).
Errors print as a clean message on stderr with exit code 1 — never a raw traceback: