git merge-base --is-ancestor <commit> <commit>
--is-ancestor Checks if the first <commit> is an ancestor of the second <commit>, 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.
e.g.
git merge-base --is-ancestor origin/master master