Skip to content

Branching (b*)

Branching commands in Hug simplify managing local and remote branches. Prefixed with b for "branch", they provide intuitive ways to list, switch, create, delete, and query branches with safety checks and clear output.

These commands are implemented as Git aliases and scripts in the Hug tool suite, wrapping Git's branch operations for better usability, including interactive selection, color highlighting, and formatted views.

Quick Reference

CommandMemory HookSummary
hug bBranch checkoutSwitch to an existing branch or pick interactively
hug blBranch ListList local branches
hug blaBranch List AllList local and remote branches
hug blrBranch List RemoteList remote branches only
hug bllBranch List LongDetailed local branch list with tracking info
hug bcBranch CreateCreate a new branch and switch to it
hug brBranch RenameRename the current branch
hug bdelBranch DELete (safe)Delete merged local branch
hug bdelfBranch DELete ForceForce-delete local branch
hug bdelrBranch DELete RemoteDelete remote branch
hug bpullBranch PullSafe fast-forward pull (fails if merge/rebase needed)
hug bpullrBranch Pull RebasePull with rebase (linear history)
hug bwcBranch Which ContainBranches containing a commit
hug bwpBranch Which PointBranches pointing at an object
hug bwncBranch Which Not ContainBranches missing a commit
hug bwmBranch Which MergedBranches merged into a commit
hug bwnmBranch Which Not MergedBranches not merged into a commit

Listing Branches

hug b [branch]

  • Description: Switch (checkout) to an existing local branch. If no branch is specified, shows an interactive menu of local branches for selection.
  • Example:
    shell
    hug b main                 # Switch to main branch
    hug b                      # Interactive menu to select branch
    hug b feature/new-ui       # Switch to feature branch
  • Safety: Interactive mode prevents accidental switches. Always checks if you're in a Git repo.

hug bl

  • Description: List local branches in short format, sorted alphabetically. The current branch is marked with an asterisk (*).
  • Example:
    shell
    hug bl    # List all local branches
  • Safety: Read-only operation; no changes to repo state.

hug bla

  • Description: List all branches (local and remote) in short format.
  • Example:
    shell
    hug bla   # List all branches including remotes
  • Safety: Read-only.

hug blr

  • Description: List remote branches only in short format.
  • Example:
    shell
    hug blr   # List remote branches
  • Safety: Read-only.

hug bll

  • Description: List local branches in long format with details: short commit hash, upstream tracking info (e.g., ahead/behind counts), and the latest commit message title. Current branch is highlighted in green and marked with *. Branches are left-aligned for readability.
  • Example:
    shell
    hug bll   # Detailed local branch listing
  • Safety: Read-only; displays tracking info like git branch -vv but with commit subjects.

Branch Creation / Modification

hug bc <branch-name>

  • Description: Create a new branch and switch to it.
  • Example:
    shell
    hug bc new-feature    # Create and switch to new-feature
  • Safety: Non-destructive; creates from current HEAD.

hug br <new-name>

  • Description: Rename the current branch to a new name.
  • Example:
    shell
    hug br updated-feature  # Rename current branch
  • Safety: Prompts for confirmation if the new name exists.

Branch Deletion

hug bdel <branch>

  • Description: Safely delete a local branch (only if fully merged into current branch).
  • Example:
    shell
    hug bdel old-feature    # Safe delete if merged
  • Safety: Fails if unmerged; requires confirmation.

hug bdelf <branch>

  • Description: Force-delete a local branch, even if unmerged.
  • Example:
    shell
    hug bdelf risky-branch  # Force delete unmerged branch
  • Safety: Double-prompts for confirmation to prevent accidents.

hug bdelr <branch>

  • Description: Delete a remote branch from the origin remote.
  • Example:
    shell
    # First, list remote branches to find the one to delete
    hug blr
    # Then, delete the desired branch by name
    hug bdelr old-remote-feature
  • Safety: Prompts for confirmation before deleting.

Pulling Branches

Hug provides safe, intuitive pull commands under the b* prefix, emphasizing fast-forward safety by default while offering rebase for linear histories.

hug bpull

  • Description: Safe fast-forward pull from upstream. Succeeds only if your local branch can fast-forward (no local divergence); aborts otherwise to prevent unintended merges or rewrites. Ideal for verifying sync before critical operations like tagging or releasing.
  • Example:
    shell
    hug bpull    # Pull if fast-forward possible; fails safely if diverged
  • Safety: Ultra-safe - aborts on any need for merge/rebase, prompting you to inspect with hug sl or use hug bpullr.

hug bpullr

  • Description: Pull with rebase, replaying your local commits on top of remote changes for a clean, linear history. Use when you've diverged locally (e.g., after committing features).
  • Example:
    shell
    hug bpullr   # Pull and rebase for linear history
  • Safety: Non-destructive to remote history, but may require conflict resolution. Aborts on issues; resume with hug rbc or abort with hug rba.

Branch Queries (bw*)

These commands help inspect which branches relate to specific commits or states.

hug bwc [<commit>]

  • Description: Show branches that contain a specific commit (in their history). Defaults to HEAD.
  • Example:
    shell
    hug bwc a1b2c3    # Branches containing commit a1b2c3
    hug bwc           # Branches containing HEAD
  • Safety: Read-only.

hug bwp [<object>]

  • Description: Show branches that point exactly at a specific object (e.g., commit). Defaults to HEAD.
  • Example:
    shell
    hug bwp HEAD       # Branches pointing at HEAD
  • Safety: Read-only.

hug bwnc [<commit>]

  • Description: Show branches that do NOT contain a specific commit. Defaults to HEAD.
  • Example:
    shell
    hug bwnc HEAD      # Branches not containing HEAD
  • Safety: Read-only.

hug bwm [<commit>]

  • Description: Show branches merged into a specific commit (defaults to HEAD).
  • Example:
    shell
    hug bwm            # Branches merged into HEAD
  • Safety: Read-only.

hug bwnm [<commit>]

  • Description: Show branches NOT merged into a specific commit (defaults to HEAD).
  • Example:
    shell
    hug bwnm           # Branches not merged into HEAD
  • Safety: Read-only.

Tips

  • Use hug b to review branch status and easily switch via an interactive menu.
  • For creating a branch from an existing one: hug bc <new> <existing> (e.g., hug bc new-feature existing-feature).
  • Always backup work with hug w backup before deleting branches.
  • Use hug blr to list remote branches before deleting one with hug bdelr.
  • Queries like bwc and bwm are useful for cleanup before bdel.

See Status & Staging for checking changes after branching operations.

Released under the Apache 2.0 License.