Reputation: 347
I'm kinda new to Git and I have to compare the HEAD from a lokal branch with a remote branch.
On the lokal branch I get the HEAD with the following command:
git rev-parse --short HEAD
root@debian:xxxx# git rev-parse --short HEAD
469xxx
But how can I get the short HEAD of a remote branch? For Example:
https://github.com/openssl/openssl
The lastest short HEAD is there "cded951"
In my case, getting the HEAD and comparing it does it.
If local HEAD != remote HEAD do xyz
For this check I need the remote HEAD of my github branch.
best regards :)
Solution:
git remote update
if ! git diff --quiet origin/master; then
echo "the branch is different!"
else
echo "the branch is equal!"
fi
Upvotes: 1
Views: 6610
Reputation: 311298
To check if your local branch differs from the associated remote tracking branch (assuming you are on the master
branch):
git remote update
if ! git diff --quiet origin/master; then
echo "the branch is different!"
fi
You could also write instead:
git diff --quiet @{u}
Where @{u}
refers to the remote tracking branch, so this would work for any local branch that is tracking a remote branch.
Upvotes: 2
Reputation: 2434
Run rev-parse
on the local copy of the remote branch
git fetch
git rev-parse --short origin/master
Upvotes: 2