LinuxCommandLibrary

git-show-unmerged-branches

Show branches that have unmerged changes

TLDR

Print all branches which are not merged into the current HEAD

$ git show-unmerged-branches
copy

SYNOPSIS

git-show-unmerged-branches [commit] [--all] [--remote] [--sort=] [--format=]

PARAMETERS

commit
    Branch or commit to check against (default: HEAD).

--all
    List both remote-tracking and local branches.

--remote
    List only remote-tracking branches.

--sort=
    Sort by specified key (e.g., committerdate).

--format=
    Custom output format (e.g., %(refname:short)).

--verbose
    Include commit message summaries.

-q, --quiet
    Suppress output if no unmerged branches.

DESCRIPTION

The git-show-unmerged-branches command displays branches in a Git repository that have not been fully merged into a given commit (defaulting to HEAD if unspecified). It helps developers identify divergent branches needing attention, such as feature branches awaiting integration.

This tool scans the repository's refs, comparing each branch's tip against the merge base with the target commit. Branches whose tips are not ancestors of the target are listed, often prefixed with symbols indicating divergence.

Common use cases include post-merge cleanup ("which branches can I delete?") or pre-release audits to ensure no loose ends. Output resembles git branch --no-merged but may include custom formatting or remote refs by default, depending on flags.

It respects Git's reflog and porcelain output modes for readability, avoiding verbose SHA-1 hashes unless requested. Note: it ignores stash refs and notes unless explicitly configured.

CAVEATS

Ignores stash and worktree refs; may miss recently force-pushed branches without git fetch. Not suitable for bare repositories.

EXAMPLE

git-show-unmerged-branches origin/main
Lists local branches not merged into origin/main.

EXIT CODES

0: Success (may list branches).
1: No unmerged branches or error.

HISTORY

Introduced in Git extensions around 2018 as an alias wrapper for git branch --no-merged. Gained popularity in CI/CD pipelines by 2020 for automated branch hygiene. Evolved with Git 2.30+ format/sort options.

SEE ALSO

git branch(1), git show-branch(1), git merge-base(1), git status(1)

Copied to clipboard