git ls-remote origin -h refs/heads/master
given by brool is the lightest way to just check if something at all has changed in the remote.
Starting from the local head:
$ git log -1 --oneline @
9e1ff307c779 (HEAD -> master, tag: v5.15-rc4, origin/master, origin/HEAD) Linux 5.15-rc4
I see that my pulled origin is up to date at that tag. git status
says so too. But that is only the local up to date, the (fast-forward) merge after a fetch.
To check if the remote HEAD went somewhere, and also master, and maybe some new tags:
$ git ls-remote origin HEAD master --tags 'v5.1[56]-rc[345]*'
84b3e42564accd94c2680e3ba42717c32c8b5fc4 HEAD
84b3e42564accd94c2680e3ba42717c32c8b5fc4 refs/heads/master
71a6dc2a869beafceef1ce46a9ebefd52288f1d7 refs/tags/v5.15-rc3
5816b3e6577eaa676ceb00a848f0fd65fe2adc29 refs/tags/v5.15-rc3^{}
f3cee05630e772378957a74a209aad059714cbd2 refs/tags/v5.15-rc4
9e1ff307c779ce1f0f810c7ecce3d95bbae40896 refs/tags/v5.15-rc4^{}
HEAD is still on the same branch, but not the same commit anymore. That local @
commit stays with the v5.15-rc4 tag. This is about the same info as on top of the summary sheet on kernel.org git:
Branch: master <commit message> <author> age: 2 hours
Only that ls-remote
collects less information - but then again only me I know that I am on 9e1ff...
aka v5.15-rc4.
Instead of naming refs (HEAD, master) or tags one can also get a list of heads or branches from any repo:
$ git ls-remote --heads git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
af06aff2a0007976513134dfe993d55992dd866a refs/heads/akpm
20bcee8e95f783c11a7bea1b6a40c70a37873e0a refs/heads/akpm-base
a25006a77348ba06c7bc96520d331cd9dd370715 refs/heads/master
4d5a088c93cea1c821d02a2217c592391d9682e2 refs/heads/pending-fixes
4de593fb965fc2bd11a0b767e0c65ff43540a6e4 refs/heads/stable
Here a URL replaces "origin".
How do I check whether the remote repository has changed and I need to
pull?
If you ask like that, just pull.
How do I check whether the remote repository has finally done something and I want to pull?
Then you fetch and check and merge.
With single git commands:
$ git rev-list -1 master
9e1ff307c779ce1f0f810c7ecce3d95bbae40896
$ git rev-list -1 @
9e1ff307c779ce1f0f810c7ecce3d95bbae40896
This by itself does not say much, but suppose I know I did not commit anything, then:
$ git ls-remote origin HEAD master
60a9483534ed0d99090a2ee1d4bb0b8179195f51 HEAD
60a9483534ed0d99090a2ee1d4bb0b8179195f51 refs/heads/master
Will tell me that the remote has changed. It really has since last edit. kernel.org says Age: 46 min.
about this last commit on master.
After git fetch
:
$ git rev-list -1 master
9e1ff307c779ce1f0f810c7ecce3d95bbae40896
$ git rev-list -1 FETCH_HEAD
60a9483534ed0d99090a2ee1d4bb0b8179195f51
$ git log --oneline ..FETCH_HEAD
60a9483534ed (origin/master, origin/HEAD) Merge tag 'warning-fixes-20211005' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
f6274b06e326 Merge tag 'linux-kselftest-fixes-5.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
ef31499a87cf fscache: Remove an unused static variable
d9e3f82279bf fscache: Fix some kerneldoc warnings shown up by W=1
bc868036569e 9p: Fix a bunch of kerneldoc warnings shown up by W=1
dcb442b13364 afs: Fix kerneldoc warning shown up by W=1
c0b27c486970 nfs: Fix kerneldoc warning shown up by W=1
84b3e42564ac Merge tag 'media/v5.15-3' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
b60be028fc1a Merge tag 'ovl-fixes-5.15-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs
df5c18838ea8 Merge tag 'mips-fixes_5.15_1' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux
206704a1fe0b media: atomisp: restore missing 'return' statement
740da9d7ca4e MIPS: Revert "add support for buggy MT7621S core detection"
1dc1eed46f9f ovl: fix IOCB_DIRECT if underlying fs doesn't support direct IO
2f9602870886 selftests: drivers/dma-buf: Fix implicit declaration warns
a295aef603e1 ovl: fix missing negative dentry check in ovl_rename()
Now I have all the information locally, but have not merged (yet). I also have all the objects downloaded. git show HASH
or git diff HASH
work.
In this case the merge is almost a no-op: fast-forward to the last commit and no extra (real) merge, let alone conflicts. This can be made sure by --ff-only:
$ git merge --ff-only FETCH_HEAD
Updating 9e1ff307c779..60a9483534ed
Fast-forward
...
...
So how can I know when to pull? As soon as these two hashes are/will, be different: Updating 9e1ff307c779..60a9483534ed Fast-forward
. They can not be the same, that would be "nothing to update".
The newest reflog commits say the same:
$ git log -10 --oneline -g
60a9483534ed (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: merge 60a9483534ed0d99090a2ee1d4bb0b8179195f51: Fast-forward
9e1ff307c779 (tag: v5.15-rc4) HEAD@{1}: pull: Fast-forward
Looking at this, a new tag appearing is maybe the best trigger and also target in this case; that leads back to the git ls-remote origin --tags PATTERN
.
...and don't tell me git remote show
is another method:
show Gives some information about the remote .
With -n option, the remote heads are not queried first with git ls-remote ; cached information is used instead.