Will Murphy's personal home page

git alias for diff similar to what GitHub shows

This command shows what’s added to a project by the current branch, ignoring changes to origin/main since the current branch diverged. I think this is basically what is shown on PRs in GitHub:

git diff $(git merge-base origin/main HEAD)..HEAD

I find this a bit much to type, so I’ve added the git alias bdiff (for “branch diff”) like so:

git config --global alias.bdiff '!f() { git diff $(git merge-base HEAD origin/main) HEAD "$@"; }; f'