libra branch

Command reference for `libra branch`

Create, delete, rename, inspect, or list branches.

Alias: br

Synopsis

libra branch [<new_branch>] [<commit_hash>]
libra branch [--create-reflog] -f <name> [<start-point>]
libra branch [-t | --track[=direct|inherit] | --no-track] <new_branch> [<start-point>]
libra branch -l [-r | -a] [--contains <commit>] [--no-contains <commit>] [--points-at <object>] [--merged [<commit>]] [--no-merged [<commit>]] [--sort <key>] [--no-sort] [--ignore-case] [--format <format>] [--column[=<mode>]] [-v | --verbose]
libra branch -d <name>
libra branch -D <name>
libra branch -m [<old>] <new>
libra branch (-c | -C) [<old>] <new>
libra branch -u <upstream> [<branch>]
libra branch --unset-upstream [<branch>]
libra branch --edit-description [<branch>]
libra branch --show-current

Description

libra branch manages local and remote-tracking branch references stored in the SQLite database. Without arguments it lists local branches in refname order (the current branch is marked with * but is not moved to the top). -v / -vv pad the name column to the longest displayed name, including a detached first line * (HEAD detached at <abbrev7>). -a prefixes remote-tracking names as remotes/<remote>/<branch>; -r omits that remotes/ prefix. A cached remote HEAD prints as remotes/<remote>/HEAD -> <remote>/<branch> on -a and <remote>/HEAD -> <remote>/<branch> on -r (JSON keeps the full refs/remotes/<remote>/HEAD name). When given a positional <new_branch> argument it creates a new branch pointing at HEAD (or at <commit_hash> when provided).

Deletion comes in two flavours: -d performs a safe delete that checks whether the branch has been fully merged into the current branch before removing it, while -D force-deletes regardless of merge status. Both refuse to delete the branch you are currently on.

branch -f <name> [<start-point>] creates a new branch or resets an existing one. An existing branch cannot be reset while it is checked out in this or another worktree. Protect and archive metadata also block -f with LBR-POLICY-001; --force does not override those policies. Switch the worktree to another branch or explicitly lift the policy before retrying. A reset reports Reset branch (or data.action = "reset" with --json) and records the old and new tips in the branch reflog. -f applies only to branch creation/reset in Libra. It is not Git's shorthand for forced deletion or renaming: use -D to force-delete; forced rename (-M) is not supported.

The --contains and --no-contains filters (aliased as --with and --without) let you narrow the branch list to those whose history does or does not include a particular commit, defaulting to HEAD when the commit argument is omitted. --points-at <object> lists branches whose tip is exactly the resolved commit; annotated tag names and full refs/tags/... names are peeled recursively to their target commit. --merged [<commit>] / --no-merged [<commit>] list branches already merged (or not yet merged) into the commit — i.e. whose tip is (or is not) reachable from it, defaulting to HEAD; this is the inverse of --contains. --sort <key> orders the list by refname, version:refname (numeric-aware), or committerdate / creatordate (the tip commit's committer date), with a leading - reversing. When the flag is absent, the Git-compatible branch.sort config default applies (strict local → global → system cascade; an invalid value fails closed with LBR-CLI-002 and an unreadable local/global scope with LBR-IO-001, before any listing output — except a future-schema global store, newer than this binary, which is skipped with a one-time warning; see LBR-CONFIG-001). Unlike the flag, the config default neither implies --list nor suppresses the unborn-HEAD line, matching Git. Documented narrowing: Git stacks repeated branch.sort values into a multi-key sort; Libra applies only the last value of the winning scope. --ignore-case makes list sorting case-insensitive.

Branch query forms (bare list, -l/-r/-a, --show-current, -v, list filters such as --contains/--merged/--sort/--format/--column, and an already-configured idempotent -u) do not write an Operation v2 entry — they no longer appear in libra op log. Mutating forms (create, delete, rename, copy, non-idempotent -u, --unset-upstream, --edit-description, branch reset, …) still record one operation each.

Options

Flag Long Value Description
<new_branch> positional Create a new branch pointing at HEAD or <commit_hash>
<commit_hash> positional (requires new_branch) Base commit for the new branch
-l --list List branches (default when no action is specified)
-D --delete-force <name> Force-delete a branch, even if not fully merged
-d --delete <name> Safe-delete a branch (must be fully merged)
-u --set-upstream-to <upstream> [<branch>] Set upstream tracking for the current branch, or for <branch> when given. A local branch name writes branch.<name>.remote=. and branch.<name>.merge=refs/heads/<upstream>. Setting a branch as its own upstream prints a warning and writes nothing.
-t --track[=direct|inherit] When creating a branch, set up tracking from the start-point (direct, default) or copy the start-point branch's upstream (inherit). A commit hash start-point is refused (LBR-CLI-003, exit 129; Git uses 128 — intentional, ADR-HF-02) and creates nothing. Combined with -d / -m / --list, or used alone, --track is ignored.
--no-track When creating a branch, do not write tracking configuration.
--unset-upstream [branch] Remove upstream tracking for the current branch or the named branch
--edit-description [branch] Edit the branch's description (branch.<name>.description) in the configured editor; an empty/comment-only buffer unsets it. Defaults to the current branch.
--show-current Print the current branch name or detached HEAD state
-m --move <old> <new> or <new> Rename a branch; with one argument renames the current branch
-c --copy <old> <new> or <new> Copy a branch (and its upstream config) to a new name, keeping the source; fails if the destination exists
-f --force <name> [<start-point>] Create the branch, or reset an existing branch that is not checked out or protected/archived (Git's git branch -f); without it an existing name is refused with fatal: a branch named '<name>' already exists
--create-reflog Accepted for parity: branch <name> and branch -f already record branch reflog entries by default, so this selects the existing default
--no-sort Clear the command-line sort keys and the configured branch.sort, falling back to refname order; a later --sort wins again (last one wins in either direction)
-C --copy-force <old> <new> or <new> Like -c, but overwrite the destination if it exists
-r --remotes Show remote-tracking branches only
-a --all Show local and remote-tracking branches
--contains [commit] (default HEAD) Only list branches containing the commit. Alias: --with
--no-contains [commit] (default HEAD) Only list branches not containing the commit. Alias: --without
--points-at <object> Only list branches whose tip points at the resolved commit; annotated tags are peeled
--merged [commit] (default HEAD) Only list branches already merged into the commit (tip reachable from it)
--no-merged [commit] (default HEAD) Only list branches not yet merged into the commit
--sort <key> Sort the list by refname, version:refname (v:refname), committerdate/creatordate/authordate (the tip commit's committer date — or author date for authordate), objectsize (the tip object's byte size), or objectname (the tip commit's object id); a leading - reverses (use --sort=-committerdate for the dash form). Overrides the branch.sort config default
--ignore-case Sort branch names case-insensitively where applicable
--format <format> Render each branch with a for-each-ref format string (e.g. %(refname:short), %(objectname), %(HEAD), %(upstream), %(if)…%(end)). Replaces the default * name listing (and -v/--column); shares the for-each-ref atom engine
--column[=<mode>] always / auto / never Lay the branch list out in columns instead of one per line (bare --column means always; auto only when stdout is a terminal). Column mode shows plain, uncolored names. Columns follow Git's layout: the slot width is the widest rendered entry plus one padding space (measured in terminal display width, so CJK/combining names align), column count is bounded by COLUMNS (default 80) and the list length, and an entry wider than COLUMNS degrades to one full name per line without truncation. When column mode is actually enabled, combining it with -v/--verbose is refused with exit 128 and options '--column' and '--verbose' cannot be used together; --no-column, --column=never, and non-TTY --column=auto do not trigger it.
--no-column Do not lay the branch list out in columns (equivalent to --column=never), countermanding an earlier --column (last one wins). Branches list one-per-line by default, so on its own this is a no-op.
-v --verbose List each branch with its tip's short sha and commit subject. Repeat (-vv) to also show the upstream-tracking segment [<upstream>: ahead N, behind M] (the same counts status reports; they are omitted when the remote-tracking ref has not been fetched, or when the counts cannot be computed — the latter with a warning; nothing shown for a branch with no configured upstream). Combining -v with an actually enabled --column is refused with exit 128; --no-column, --column=never, and non-TTY --column=auto remain valid.

Flag examples

# Create a branch from HEAD
libra branch feature-x

# Create a branch from another branch or commit
libra branch feature-x main
libra branch hotfix abc1234

# Create a branch that tracks its start-point (or copies that branch's upstream)
libra branch --track t1 main
libra branch --track=inherit t3 t1
libra branch --no-track t4 main

# List local branches
libra branch -l

# List all branches (local + remote)
libra branch -l -a

# Remote-tracking list includes the cached remote HEAD symlink
# (e.g. remotes/origin/HEAD -> origin/main on -a; origin/HEAD -> origin/main on -r)
libra branch -a
libra branch -r

# List branches with their tip sha and commit subject
libra branch -v

# List branches containing the latest release tag
libra branch --contains v2.0

# List branches already merged into main (or not yet merged)
libra branch --merged main
libra branch --no-merged main

# Sort branches by name (version-aware), or reversed
libra branch --sort version:refname
libra branch --sort=-refname

# Sort branches by tip commit date (most recent first)
libra branch --sort=-committerdate

# Render each branch with a for-each-ref format string
libra branch --format='%(refname:short) %(objectname:short)'

# List branches that do NOT contain HEAD
libra branch --no-contains

# Safe-delete a merged branch
libra branch -d topic

# Force-delete regardless of merge status
libra branch -D experiment

# Rename current branch
libra branch -m new-name

# Rename any branch
libra branch -m old-name new-name

# Copy a branch (keeping the original)
libra branch -c old-name new-name

# Set upstream tracking
libra branch -u origin/main
libra branch -u main alpha              # Point alpha at the local branch main

# Clear upstream tracking for the current branch
libra branch --unset-upstream

# List branches whose tip is exactly HEAD
libra branch --points-at HEAD

# Show current branch name
libra branch --show-current

# JSON output for agents
libra branch --json --show-current

branch diff (Libra extension)

libra branch diff [<BASE>] [<BRANCH>] shows what <BRANCH> changes relative to <BASE> — tip-to-tip (the working tree is never involved), byte-identical to libra diff <BASE>..<BRANCH>. Defaults: <BRANCH> = the current branch; <BASE> = its configured upstream (no upstream → an error with setup hints). --merge-base switches to three-dot semantics. Curated passthrough: --stat, --name-only, --name-status, --exit-code and -- <path>...; the full diff surface lives on libra diff. --json emits the diff schema. Exit 0 even with differences (use --exit-code for 1), 129 usage/unknown side, 128 fatal. Note: diff is a reserved verb — libra branch -v diff is refused rather than creating a branch named diff (use libra switch -c diff if you really want one).

branch reset (Libra extension)

libra branch reset <BRANCH> <TARGET> moves a local branch tip to any commit-ish through the authoritative SQLite transaction (reference update + a reflog entry for the branch) — the index and working tree are never touched. The currently checked-out branch is refused (use libra reset, which moves HEAD/index/worktree consistently). Protected or archived branches (libra metadata set --branch <b> protect|archive true) refuse with LBR-POLICY-001; this branch reset form has no --force, and branch -f cannot bypass the policy — lift the flag explicitly (metadata unset), reset, then re-protect (auditable). The same policy is enforced inside libra update-ref's transaction for refs/heads/* updates and deletes, so plumbing is not a bypass. Identical re-runs within the operation log's 5-second dedup window are refused. reset joins diff as a reserved verb (libra switch -c reset still creates such a branch).

Common Commands

libra branch feature-x                  # Create a branch from HEAD
libra branch feature-x main             # Create a branch from another branch
libra branch -d topic                   # Delete a fully merged branch
libra branch -D topic                   # Force-delete a branch
libra branch --set-upstream-to origin/main
                                        # Set upstream for the current branch
libra branch --json --show-current      # Structured JSON output for agents

Human Output

  • List: prints the branch list in refname order with * marking the current branch; -v/-vv align the name column to the longest name
  • Safe delete: Deleted branch feature (was abc123...)
  • Rename: Renamed branch 'old' to 'new'
  • Copy: Copied branch 'old' to 'new'
  • Unset upstream: Branch 'main' no longer tracks an upstream branch
  • Local upstream: branch 'alpha' set up to track 'main'.
  • Self-upstream: warning: not setting branch 'main' as its own upstream (exit 0, no write)
  • --show-current: prints the current branch name, or HEAD detached at <hash> when detached

Structured Output (JSON examples)

--json / --machine uses action to distinguish operations:

{
  "ok": true,
  "command": "branch",
  "data": {
    "action": "create",
    "name": "feature",
    "commit": "abc123..."
  }
}

List action:

{
  "ok": true,
  "command": "branch",
  "data": {
    "action": "list",
    "branches": [
      { "name": "main", "current": true, "commit": "abc1234..." },
      { "name": "feature", "current": false, "commit": "def5678..." }
    ]
  }
}

Show-current action:

{
  "ok": true,
  "command": "branch",
  "data": {
    "action": "show-current",
    "name": "main",
    "detached": false,
    "commit": "abc1234..."
  }
}

Supported actions:

  • list: branches
  • create: name, commit
  • delete: name, commit, force
  • rename: old_name, new_name
  • set-upstream: branch, upstream
  • unset-upstream: branch
  • show-current: name, detached, commit

Design Rationale

Why --contains/--no-contains with aliases --with/--without?

The --contains and --no-contains flags mirror Git for compatibility, but Libra adds shorter --with and --without aliases. These read more naturally in scripts (libra branch --with v2.0) and reduce typing. The flags accept an optional commit argument that defaults to HEAD, which covers the most common case of "which branches include my current work?"

Why SQLite-backed refs?

Git stores branch references as individual files under .git/refs/heads/. This causes problems at scale: monorepos with thousands of branches suffer from filesystem overhead, packed-refs contention, and race conditions during concurrent updates. Libra stores all references in a SQLite database (libra.db), which provides:

  • Atomic transactions: branch create/delete/rename are single-transaction operations with no risk of partial writes or corrupted ref files.
  • Efficient queries: listing branches, filtering with --contains, and upstream lookups are SQL queries rather than directory scans.
  • Concurrency safety: SQLite's WAL mode handles concurrent reads and serialized writes without external locking.
  • Consistent snapshots: operations that read multiple refs (like --contains filtering) see a consistent view of the ref store.

The trade-off is that refs are not directly inspectable as plain files. Libra compensates with structured JSON output for tooling integration.

Parameter Comparison: Libra vs Git vs jj

Feature Git Libra jj
Create branch git branch <name> libra branch <name> jj branch create <name>
Create from commit git branch <name> <commit> libra branch <name> <commit> jj branch create <name> -r <rev>
List branches git branch [-l] libra branch [-l] jj branch list
Delete (safe) git branch -d <name> libra branch -d <name> jj branch delete <name>
Delete (force) git branch -D <name> libra branch -D <name> jj branch delete <name> (always force)
Rename git branch -m <old> <new> libra branch -m <old> <new> Not supported
Copy git branch -c <old> <new> libra branch -c <old> <new> (-C to force) Not supported
Set upstream git branch -u <upstream> [<branch>] libra branch -u <upstream> [<branch>] (local branches write remote=.) N/A (no upstream concept)
Unset upstream git branch --unset-upstream [branch] libra branch --unset-upstream [branch] N/A
Show current git branch --show-current libra branch --show-current jj log -r @
Remote branches git branch -r libra branch -r jj branch list --all
All branches git branch -a libra branch -a jj branch list --all
Contains filter git branch --contains <commit> libra branch --contains <commit> jj log -r 'branches() & ancestors(<rev>)'
Merged filter git branch --merged [<commit>] / --no-merged libra branch --merged [<commit>] / --no-merged jj log -r 'branches() & ::<rev>'
Points-at filter git branch --points-at <object> libra branch --points-at <object> N/A
Sort list git branch --sort <key> libra branch --sort <key> (refname / version:refname / committerdate / creatordate / authordate / objectsize / objectname) jj branch list (revset order)
Custom format git branch --format <format> libra branch --format <format> (for-each-ref atoms; replaces * name/-v/--column) N/A
Column layout git branch --column[=<mode>] libra branch --column[=<mode>] (--no-column countermands) N/A
Verbose listing git branch -v / -vv libra branch -v (sha + subject) / -vv (+ upstream tracking) N/A
Auto-track git branch --track[=direct|inherit] / --no-track libra branch --track[=direct|inherit] / --no-track (hash start-point is 129 / LBR-CLI-003; Git 128) N/A
Structured output No --json / --machine --template
Fuzzy suggestions No Levenshtein-based "did you mean" No

Error Handling

Scenario Error Code Hint
Invalid start point or missing branch LBR-CLI-003 "use 'libra branch -l' to list branches" + fuzzy suggestions
Missing -u upstream or target branch LBR-CLI-003 Git wording (the requested upstream branch '…' does not exist / branch '…' does not exist); exit 129 (Git uses 128 — intentional, ADR-HF-02)
Too many arguments to -u LBR-CLI-002 too many arguments to set new upstream (exit 129; Git 128)
--track start-point is not a branch LBR-CLI-003 cannot set up tracking information; starting point '…' is not a branch (exit 129; Git 128 — intentional, ADR-HF-02)
Invalid branch name LBR-CLI-002 "branch names cannot contain spaces, '..', '@{', or control characters."
Branch already exists LBR-CONFLICT-002 "delete it first or choose a different name."
Current branch cannot be deleted LBR-REPO-003 "switch to a different branch first." Safe -d refusals (not fully merged, missing branch, currently checked out) exit 1; LIBRA_FINE_EXIT_CODES=1 does not change that.
Branch not fully merged (safe delete) LBR-REPO-003 the branch '…' is not fully merged plus libra branch -D … (exit 1)
Locked/internal branch LBR-CLI-003 --
HEAD is detached (rename/upstream) LBR-REPO-003 --
Failed to write refs LBR-IO-002 --
Storage query failed LBR-IO-001 --
Stored reference corrupt LBR-REPO-002 --

Issue #477 notes

a local branch as upstream (branch.<name>.remote=.) invalid -u targets exit 129 (Git: 128) --track=inherit copies the upstream of the start branch --track <commit> is refused with exit 129 (Git: 128) listed in refname order; the current branch is marked but not moved branch -d refusals exit with status 1

--separate-git-dir pointer layouts are supported: when <worktree>/.libra is a gitdir: <dir> pointer file (created by libra clone --separate-git-dir), this command resolves the real metadata directory and reads <dir>/libra.db and <dir>/objects instead of <worktree>/.libra.