I see two options. First I'll give one that answers your question literally as asked, but honestly it's not what I'd recommend. So then I'll give a solution I would consider using instead...
To avoid the merge...
You can use fetch
instead of pull
. The whole point of pull
is to be a shortcut that fetches and then does the merge automatically, so if you don't want the merge you don't have to pull. Then you would refer to the other branch using your remote tracking ref (e.g. something like remotes/origin/other_branch
when examining other_branch
).
But it's not clear to me what exactly you would diff in that case. Just diffing the branches isn't going to directly tell you what you want to know.
You could look at "their changes" by
git diff $(git merge-base remotes/origin/other_branch HEAD) remotes/origin/other_branch
and "our changes" by
git diff $(git merge-base remotes/origin/other_branch HEAD) HEAD
but then you'd essentially have to perform the merge in your mind to understand the result. So...
What you can do instead...
It sounds like you really want to avoid the commit of the merge, not the merge itself. (This is more akin to what happens when there's a conflict.) So
git pull --no-commit
Then examine the result and decide whether to edit it, commit it, or throw it out.
Even that isn't really necessary to do every single time, because a merge (as long as it hasn't been pushed) can be easily undone. So what I'd do is, let the merge happen. Examine the outcome with something like
git diff HEAD^
If you don't like the result, you can
git reset --hard HEAD^
and then perhaps rerun the pull (or just the merge) with the --no-commit
option.