1

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?

pir
  • 5,513
  • 12
  • 63
  • 101
  • This can't work: You want to compare info but not fetch the info? The only possibility I see is that you delegate the comparison to some system that already has the info. – Ulrich Eckhardt Oct 01 '21 at 19:44

1 Answers1

5

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
knittl
  • 246,190
  • 53
  • 318
  • 364
  • On the other hand, it *does* require a local repo, but that could just be `git init` and `git origin add origin `, I guess. – Code-Apprentice Oct 01 '21 at 19:32
  • 3
    @Code-Apprentice not necessarily, you can also do `git ls-remote url-to-repo ref` outside of a local repo. Thanks for asking, I will clarify this in my answer. – knittl Oct 01 '21 at 19:37