I have a script that periodically compares a local branch with its remote counterpart to see if there's any update.
To do this I use the following:
- update the... remote references? with
git remote update
- get the local commit with
git rev-parse @
- get the corresponding remote (upstream) commit with
git rev-parse @{u}
- compare the two hashes
and they appear quite efficient, especially git remote update
which is very fast in retrieving information from the remote repository.
Now I want to do a similar thing with a tag (I'm evaluating the possibility to use them to mark special commits and be able to move that mark back and forth), and using a specific one, i.e. tagged
, much like I was checking a specific branch in the first part.
But I did not find a similarly efficient sequence of commands. Let me be clear: I'm fine if a command takes several seconds to complete, I would just like to use the lightiest possible one. E.g. before finding git remote update
, I was using fetch
, which allowed me to accomplish the same result, but with much more burden (and network, repository, etc. load).
The tag is created and moved with these:
git tag tagged <hash> -f
git push --tags -f
While inspecting (obtaining the commit hash in) the working copy is as easy as before (with git rev-parse tagged
), I don't know the command to check the same on the remote.
Since I'm using this in a script, a command with a single output would be the best.
The only one which seems to come closer is ls-remote
, that I tried like this: git ls-remote --tags origin tagged
; but it's a little slow and maybe it is doing more than I need.
The other command I tried is git rev-parse --tags
, but it outputs a list, and doesn't seem to allow specifying to query the remote (of course with branches is easier, since they have an upstream associated).