Since I want to use it often, I made @jthill's answer into an alias.
Add the alias with
git config --global alias.branch-diff "!f(){ git diff $(git merge-base $1 $2) $2 "${@:3}"; }; f"
With syntax git branch-diff <arg1> <arg2> <more args>
. The 1st argument represents the master branch, which the branch in the 2nd argument split off at some point. Further arguments are passed to the diff.
Usage:
git branch-diff master other-branch --name-only
The alias expands this into this and executes it:
git diff $(git merge-base master other-branch) other-branch --name-only
git branch-diff master other-branch
The alias expands this into this and executes it:
git diff $(git merge-base master other-branch) other-branch
Bonus:
# get all file names changed
git branch-diff master other-branch --name-only
# get changes of my_file.cpp
git branch-diff master other-branch -- my_file.cpp