LinuxCommandLibrary

git-show-merged-branches

Show branches already merged into current branch

TLDR

Print all branches which are merged into the current head

$ git show-merged-branches
copy

SYNOPSIS

git-show-merged-branches [commit] [--all] [--remote]

PARAMETERS

commit
    Optional commit-ish to check merges against (default: HEAD)

-a, --all
    Include remote-tracking branches in the list

-r, --remote
    List only remote-tracking branches that are merged

-v, --verbose
    Show commit SHA and message for each merged branch

DESCRIPTION

The git-show-merged-branches command displays a list of local branches that are fully merged into the specified commit (defaults to HEAD). It helps identify stale branches ready for cleanup, improving repository hygiene.

This utility is particularly useful in team workflows where feature branches accumulate after merges. By showing only merged branches, it simplifies the process of pruning unnecessary refs without risking loss of unmerged work.

Unlike git branch, which lists all branches, this focuses solely on merged ones, often color-coded (green by default in Git) for easy identification. It supports filtering by commit and can include remotes with options.

Common use case: Run before git branch -d to safely delete merged branches. Output includes branch names with asterisks for current branch if merged.

CAVEATS

Does not verify if branches are pushed; use with git branch -d cautiously. Ignores reflog; merged status based on current refs only.
Remote branches require fetch first.

EXAMPLE USAGE

git-show-merged-branches # Local merged branches
git-show-merged-branches origin/main --all # Including remotes

OUTPUT FORMAT

Branches prefixed with * if current; green color indicates fully merged.

HISTORY

Introduced in git-extras 4.0 (2016) as a convenience wrapper around git branch --merged. Evolved to support remotes in v6.0; widely adopted in Git aliases and IDE integrations.

SEE ALSO

git-branch(1), git-show-branch(1), git-branch-delete(1)

Copied to clipboard