Dorrian
Dorrian

Reputation: 113

How can I check if a specific remote repository branch contains a specific merged branch?

I want to check if a branch on a remote Git repository contains a merged branch with a specific name. For example:

If I cloned the repository and checkout myBranch, I could do git show-ref --verify refs/heads/myFeatureBranch, but that's not what I want to do. I have to do it with a remote branch without cloning.

I already played around with git ls-remote --heads www.example.com:/repo.git, but the only thing I get is a list of remote heads. Has anyone done that before?

Upvotes: 7

Views: 3048

Answers (2)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

Git Operates Locally by Design

The distributed nature of Git is fundamentally designed around a couple of fundamental concepts:

  1. Most operations are local, with a few minor exceptions like push and ls-remote.
  2. History is calculated from commit objects.

What this means is that exploring history is a local operation, and can't be performed on a remote repository.

Remote References

The git-ls-remote command is useful in searching upstream for refs, but not for history. For example:

git ls-remote origin | egrep 'some_branch_name|merge'

will print refs on the remote that match the named branch you're looking for, or (in the case of GitHub) refs created from merged pull-requests such as:

381a77fd72ea594cfce5c82c845ad3d10bb87d71        refs/pull/99/merge

The git-ls-remote command displays refs available in a remote repository along with the associated commit IDs. However, if you want to find out what branch contains a given commit, you need access to the full history; that requires you to have a local copy.

Finding Branches Containing a Merge Commit

The best way I know to deal with this issue is the following:

  1. Fetch all branches with git fetch --all origin.
  2. Find the merge commits you want with git log --merges.
  3. Find the containing branches with git branch --all --contains <commit>.

This will give you a list of branches that contain the specified commit.

Upvotes: 1

Adam Dymitruk
Adam Dymitruk

Reputation: 129526

You can't execute commands on the remote. It is simply a sync mechanism. You will need to clone to execute the regular commands.

You may want to look up git branch -a --contains

Upvotes: 1

Related Questions