How can I check whether two branches are "even"? describes how to check if two git branches are even. However, the answers rely on having the branched fetches and updated locally. As this is part of a script and the git repos are quite big, I do not want to fetch all the info for the branches.
How do I check if two branches on a GitHub repo are even w/o having local copy of the git repo?
CodePudding user response:
git ls-remote
will print the commit hashes for a remote repository for any ref that you pass it without downloading the complete history, e.g.
git ls-remote origin master v1.0.0
Could print:
cefe983a320c03d7843ac78e73bd513a27806845 refs/heads/master
f665776185ad074b236c00751d666da7d1977dbe refs/tags/v1.0.0
From there, extract the hashes and compare them.
ls-remote
doesn't even require a local Git repository; you can call it from anywhere as long as you pass it a valid "remote":
git ls-remote git://git.kernel.org/pub/scm/git/git.git master v1.0.0