How can use merge-base
with Git
on a remote repository without checking it out? Using ls-remote
works fine e.g. for determining branches like this:
git ls-remote --heads $REPO_URL/$REPO_NAME
The documentation contains no clue, wether the use of merge-base
with ls-remote
is possible. Maybe it is also possible, to use alternatives to merge-base
to find the common ancestor for branches/commits.
At the moment, i have to checkout the repository locally, which takes a lot of time for big projects.
In general, no:
ls-remote
shows you the commit IDs on the remote for the requested references, but for each commit-ID, if you do not have that commit locally you cannot determine its parent commit(s).There is no need to check out the commits though. Just use
git fetch
to bring over any missing objects, and you will then have the full repository history. A futuregit fetch
will continue to bring over only missing objects, which will be new objects that you would need anyway in order to find items.I do not know what you are attempting to do with
git merge-base
but it requires only commit-IDs for all but the new--fork-point
operation, where it uses your local reflog and therefore requires a local reference-name. For instance:This tells me that the merge-base of
9b1c2a...
andbba6acb...
isebc5da3...
. (All of these are commit IDs within the repository containing the source to git itself.) And:tells us that the merge-base is contained within four remote branches:
maint
,master
,next
, andpu
, plus the local branchmaster
(which is in sync withorigin/master
anyway). More interestingly:tells us that the merge-base is tagged as git version 2.0.2, so these two other commits (chosen arbitrarily out of the log) have common ancestry at that particular tag.