I can list all branches containing a certain commit using git branch --list --contains just fine. But as explained in the related question on how to list all br
One possible solution using the plumbing commands git-for-each-ref and git merge-base (the latter suggested by Joachim himself):
#!/bin/sh
# git-branchesthatcontain.sh
#
# List the local branches that contain a specific revision
#
# Usage: git branchthatcontain
#
# To make a Git alias called 'branchesthatcontain' out of this script,
# put the latter on your search path, and run
#
# git config --global alias.branchesthatcontain \
# '!sh git-branchesthatcontain.sh'
if [ $# -ne 1 ]; then
printf "%s\n\n" "usage: git branchesthatcontain "
exit 1
fi
rev=$1
git for-each-ref --format='%(refname:short)' refs/heads | \
while read ref; do
if git merge-base --is-ancestor "$rev" "$ref"; then
printf "%s\n" "$ref"
fi;
done
exit $?
The script is available at Jubobs/git-aliases on GitHub.
(Edit: thanks to coredump for showing me how to get rid of that nasty eval.)