Find Git branches that contain a commit
Check which branch and tag histories contain a commit, refresh remote-tracking refs, and distinguish ancestry from a backported patch.
git branch --contains COMMIT lists local branches whose histories include that exact commit. It is useful for checking whether a fix has reached a release branch, provided the fix was merged with its original ancestry intact.
List matching refs
git branch --contains a1b2c3d
git branch -a --contains a1b2c3d
git branch -r --contains a1b2c3d
git tag --contains a1b2c3d
-a includes local and remote-tracking branches; -r limits the result to remote-tracking branches. Refresh those refs with git fetch --all --prune if the answer must reflect the latest accessible remotes. Custom refspecs and shallow history can limit what is available locally.
Inspect release branches and tags
git for-each-ref --contains=9f8e7d6 --format='%(refname:short)' refs/remotes/origin/release/
git tag --contains 9f8e7d6 --sort=version:refname
Adjust the release-branch prefix to your naming convention. Version sorting orders tag names; the first result is not proof of the first deployed release. Prereleases, backports, independent release lines, and deployment timing require release records as well.
Test one target
git merge-base --is-ancestor a1b2c3d main
Exit status 0 means the commit is reachable from main; 1 means it is not. Treat any other status as a failed check, not as a negative answer. --contains produces a list, while --is-ancestor provides a precise predicate for automation.
Why a backport may not appear
Cherry-picking usually creates a new commit ID, so the target need not contain the original commit. git cherry main feature-x can identify equivalent individual patches, but it is not a general detector for squash merges or a proof that the current application still contains the fix. A later revert can also remove a fix's effect while leaving its original commit in the ancestry.
Add author and date context
git for-each-ref --contains=a1b2c3d \
--format='%(refname:short) %(authorname) %(authordate:iso8601)' \
refs/heads/ refs/remotes/
These fields describe each branch tip's commit, not when the branch was created or when the requested fix was merged. Use them as inspection context and apply any author or date filter to the intended field.
See git-branch, git-for-each-ref, and git-tag.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan