2

I simply want to get a non-zero exit code if there is a diff between a local branch and the remote tracking branch.

For example, say the local branch is foo, and I have it checked out, so the diff command would be:

git fetch origin
git diff --exit-code remotes/origin/foo

However, my question is - is there a generic/programmatic way to run this kind of diff command for any local branch? I want to diff a local branch with the remote tracking branch, generically.

Nimeshka Srimal
  • 8,012
  • 5
  • 42
  • 57
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

0

To reliably programmatically get the upstream for your current branch, you can use:

HEAD@{upstream}

so in this context, it would be:

git diff HEAD HEAD@{upstream}

and for all I know, that might be the default, when you run:

git diff

without anymore arguments; I prefer to be explicit though.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817