How about: git fetch && git branch -r --contains <commit-id>
I may have overlooked some plumbing too, but as far as I can tell, the most direct way to test if commitA is an ancestor of commitB is to check if git merge-base commitA commitB
is commitA
. Fetch first, and then since they may be branches, use rev-parse to get an SHA1 for commitA:
if [ "$(git rev-parse $commitA)" == "$(git merge-base $commitA $commitB)" ]; then ...; else ...; fi
Wrap that up in an alias and you should be set.
As for during push and fetch (pull), those are implemented in C, so they're not directly calling any exposed plumbing commands.
git fetch
+ git branch -r
is the best you could get.
You can hack the git protocol to give this result, but there are no plumbing you can use afaik. See section 5 for details. Just hack the "have" command and check if the server NAK.
A even easier hack is just try to push that commit, see if the server want it.