From Git 1.8.0, this is supported as an option to merge-base:
git merge-base --is-ancestor <maybe-ancestor-commit> <descendant-commit>
From the man page:
–is-ancestor
Check if the first is an ancestor of the second ,
and exit with status 0 if true, or with status 1 if not. Errors are
signaled by a non-zero status that is not 1.
For example:
git merge-base --is-ancestor origin/master master; echo $?