{"thread":{"id":"16800","subject":"how to check remote git repo for updates without pull/fetch","startedAt":"2008-12-19T16:15:27Z","lastAt":"2008-12-21T09:53:38Z","messageCount":7,"participants":["Ivan Zorin","Shawn O. Pearce","James Cloos","David Aguilar","Boyd Stephen Smith Jr."],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98357","messageId":"494BC89F.9070107@gmail.com","threadId":"16800","inReplyTo":null,"subject":"how to check remote git repo for updates without pull/fetch","fromName":"Ivan Zorin","fromEmail":"ivan.a.zorin@gmail.com","sentAt":"2008-12-19T16:15:27Z","receivedAt":"2008-12-19T16:15:27Z","isPatch":false,"sender":{"key":"ivan.a.zorin@gmail.com","avatar":null},"body":"Hello. I have not very hard question, but I don't know how to better do\nit - could you tell me, please, does exist some way to check remote git\nrepository for updates without downloading any essential files? I\nsuppose, that such command should just type something like: \"already\nupdated\", if current working tree identical to remote repo, and\nsomething like \"there is some updates in remote repo\", if remote repo\nhas some new commits and/or branches. Thanks.\n"},{"id":"98358","messageId":"20081219163300.GT32487@spearce.org","threadId":"16800","inReplyTo":"494BC89F.9070107@gmail.com","subject":"Re: how to check remote git repo for updates without pull/fetch","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-19T16:33:00Z","receivedAt":"2008-12-19T16:33:00Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Ivan Zorin <ivan.a.zorin@gmail.com> wrote:\n> Hello. I have not very hard question, but I don't know how to better do\n> it - could you tell me, please, does exist some way to check remote git\n> repository for updates without downloading any essential files? I\n> suppose, that such command should just type something like: \"already\n> updated\", if current working tree identical to remote repo, and\n> something like \"there is some updates in remote repo\", if remote repo\n> has some new commits and/or branches. Thanks.\n\nThere aren't any commands to do it.\n\nWhat you could do is write a script based upon git ls-remote. A\nreally simple one might be:\n\n\t#!/bin/sh\n\tremote=$1\n\to=.git/remote_cache.$remote\n\tn=$o.new$$\n\tgit ls-remote $remote >$n\n\tif [ -f $o ]\n\tthen\n\t\tif diff $o $n >/dev/null\n\t\tthen\n\t\t\techo \"No changes\"\n\t\telse\n\t\t\tmv $n $o\n\t\t\techo \"Updates available\"\n\telse\n\t\tmv $n $o\n\t\techo \"New remote remembered...\"\n\tfi\n\nA much more complex one would actually rewrite refs/heads/ to\nthe correct refs/remotes/ namespace on your local repository and\ncompare the remote ref values to the local refs/remotes values.\n\nPatches for git fetch --pretend or something might be interesting.\nThough I recall a thread about this before on the MLand saying there\nwas no point.  Its not like you can see how big the download would\nbe until after its over.\n\n-- \nShawn.\n"},{"id":"98359","messageId":"494BCE37.1080204@gmail.com","threadId":"16800","inReplyTo":"494BC89F.9070107@gmail.com","subject":"Re: how to check remote git repo for updates without pull/fetch","fromName":"Ivan Zorin","fromEmail":"ivan.a.zorin@gmail.com","sentAt":"2008-12-19T16:39:19Z","receivedAt":"2008-12-19T16:39:19Z","isPatch":false,"sender":{"key":"ivan.a.zorin@gmail.com","avatar":null},"body":"\n> does exist some way to check remote git repository for updates without downloading any essential files?\nWell, actually, I think, that I've found one of possible soulution already:\nFirst, check remote repo:\n$ git ls-remote /path/to/git/repo\n<some sha1-hash>\tHEAD\n...\nThen check local repo:\n$ cat .git/HEAD\nref: refs/heads/master\n$ cat .git/refs/heads/master\n<other sha1-hash>\nSo, if both hashes identical, then current working tree with HEAD, which points to \"master\", already up-to-dated,\nbut if they don't, then there is some updates at remote repo.\n"},{"id":"98443","messageId":"m3skoi21m3.fsf@lugabout.jhcloos.org","threadId":"16800","inReplyTo":"494BC89F.9070107@gmail.com","subject":"Re: how to check remote git repo for updates without pull/fetch","fromName":"James Cloos","fromEmail":"cloos@jhcloos.com","sentAt":"2008-12-20T17:32:45Z","receivedAt":"2008-12-20T17:32:45Z","isPatch":false,"sender":{"key":"cloos@jhcloos.com","avatar":"https://gravatar.com/avatar/ec9a05787d29afe41e243e4b60bd0e2f69d757688e8f0bfe5e78bc185a3e317f?d=mp&s=160"},"body":"Here is the script I use:\n\n\n\n#!/bin/bash\n#\n# does this git repo need a pull?\n#\nl=$(git log|head -1|awk '{print $NF}')\nr=$(git ls-remote origin heads/master|awk '{print $1}')\ntest \"${r}\" != \"${l}\"\n\n\n\n\n-JimC \n-- \nJames Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6\n"},{"id":"98464","messageId":"402731c90812201541r510170tbe1d56b7261e8146@mail.gmail.com","threadId":"16800","inReplyTo":"m3skoi21m3.fsf@lugabout.jhcloos.org","subject":"Re: how to check remote git repo for updates without pull/fetch","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2008-12-20T23:41:13Z","receivedAt":"2008-12-20T23:41:13Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"2008/12/20 James Cloos <cloos@jhcloos.com>:\n>\n> #!/bin/bash\n> #\n> # does this git repo need a pull?\n> #\n> l=$(git log|head -1|awk '{print $NF}')\n> r=$(git ls-remote origin heads/master|awk '{print $1}')\n> test \"${r}\" != \"${l}\"\n>\n>\n> -JimC\n> --\n> James Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6\n>\n>\n\nHello\n\nYour script will report false positives if you run that in a branch\nwhere you've made local commits since git log's output will list a\ncommit that's not on the remote side.  Thus it'lll say 'you need to\npull' when really what happened was that you committed locally and the\nsha1 test is no longer equal.  This is one of the reasons why it's a\ngood idea to always keep your local master clean.\n\nThere's two things you can do:\n\n1. assume that you always keep your local 'master' branch clean.\nThat'll let you quickly compare your local master versus origin's\nmaster:\n\n#!/bin/sh\nremotemaster=$(git ls-remote origin heads/master | awk '{print $1}')\nlocalmaster=$(git rev-parse master)\ntest \"$remotemaster\" = \"$localmaster\"\n\n\n2. You might have a local branch that's not called master but is\ntracking origin/master.  Or, your master branch might not be clean.\nYou can accomodate that workflow with:\n\n#!/bin/sh\nremotemaster=$(git ls-remote origin heads/master | awk '{print $1}')\nbranchpoint=$(git merge-base origin/master HEAD)\ntest \"$remotemaster\" = \"$branchpoint\"\n\n\nThe difference is that we're checking against the branch point.  If\norigin/master is beyond the branch point then chances are you need to\npull.\n\n\n\n---- off topic, but related ----\n\nBTW one sound recommendation that I've heard on this list is that your\ntopic branches should really be free of any unrelated changes.\nPulling stuff in \"just because\" changes the branch.  It's no longer\njust \"topic\" -- it's now \"topic\" + whatever they happened to push\nupstream.  That has some implications in that it makes it harder to\nreview what exactly went into the specific topic/feature since the\nbranch's history now contains unrelated changes.\n\nAn advantage of keeping your topic branches clean is that you can run:\n\n    git diff $(git merge-base HEAD origin/master)\n\nin your topic branch and you'll see *only* the changes that went into\nthat branch.  If you get into the habit of pulling stuff in then\nyou'll see your changes *and* stuff you've pulled in, which probably\nhas nothing to do with the original topic/feature, etc. etc.\n\nAnyways, this is an entirely different topic/conversation and might\nnot apply to your specific circumstance but I figured I'd mention it\nnonetheless.\n\n\n-- \n    David\n"},{"id":"98465","messageId":"200812201802.57953.bss@iguanasuicide.net","threadId":"16800","inReplyTo":"402731c90812201541r510170tbe1d56b7261e8146@mail.gmail.com","subject":"Re: how to check remote git repo for updates without pull/fetch","fromName":"Boyd Stephen Smith Jr.","fromEmail":"bss@iguanasuicide.net","sentAt":"2008-12-21T00:02:53Z","receivedAt":"2008-12-21T00:02:53Z","isPatch":false,"sender":{"key":"bss@iguanasuicide.net","avatar":"https://gravatar.com/avatar/84b95eeff194b816c1568b1339e63e4b229825298664a9037b9f1ec713ead1e3?d=mp&s=160"},"body":"On Saturday 2008 December 20 17:41:13 David Aguilar wrote:\n> 2008/12/20 James Cloos <cloos@jhcloos.com>:\n> > #!/bin/bash\n> > #\n> > # does this git repo need a pull?\n> > #\n> > l=$(git log|head -1|awk '{print $NF}')\n> > r=$(git ls-remote origin heads/master|awk '{print $1}')\n> > test \"${r}\" != \"${l}\"\n> >\n> >\n> > -JimC\n> > --\n> > James Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6\n>\n> Hello\n>\n> Your script will report false positives if you run that in a branch\n> where you've made local commits since git log's output will list a\n> commit that's not on the remote side.\n\nChange the last line to:\ntest \"${r}\" != \"$(git merge-base \"${r}\" \"${l}\")\" and those false positives \nshould go away.\n\nThe script is far from a complete solution to the OPs problem though.  It only \nchecks one, specific remote branch.  It only checks against the current \nbranch.  It is the core of something that might be useful as another \nsubcommand to 'git remote' though.\n-- \nBoyd Stephen Smith Jr.                     ,= ,-_-. =. \nbss@iguanasuicide.net                     ((_/)o o(\\_))\nICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' \nhttp://iguanasuicide.net/                      \\_/     \n"},{"id":"98483","messageId":"m38wq9zwee.fsf@lugabout.jhcloos.org","threadId":"16800","inReplyTo":"402731c90812201541r510170tbe1d56b7261e8146@mail.gmail.com","subject":"Re: how to check remote git repo for updates without pull/fetch","fromName":"James Cloos","fromEmail":"cloos@jhcloos.com","sentAt":"2008-12-21T09:53:38Z","receivedAt":"2008-12-21T09:53:38Z","isPatch":false,"sender":{"key":"cloos@jhcloos.com","avatar":"https://gravatar.com/avatar/ec9a05787d29afe41e243e4b60bd0e2f69d757688e8f0bfe5e78bc185a3e317f?d=mp&s=160"},"body":">>>>> \"David\" == David Aguilar <davvid@gmail.com> writes:\n\nDavid> Your script will report false positives if you run that in a branch\nDavid> where you've made local commits since git log's output will list a\nDavid> commit that's not on the remote side.\n\nAh.  Yes.  I forgot to mention that.  Good catch.\n\nI wrote the script specifically for use with the repos created by Gentoo's\ngit eclass (used when installing packages from git repos rather than from\ntars or the like).  As such, it only needed to deal with pristine clones.\n\n-JimC\n-- \nJames Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6\n"}]}