Get only remote branches that have already been merged into master/develop

6.2k views Asked by At
git ls-remote --h <domain_specific_url>.git 'refs/heads/*' 

which lists all the branches created on remote repository.

But I would like to extend this command to use --merged option, since I would like to get lists of branches which are already merged to develop/master

something like:

git ls-remote --h <domain_specific_url>.git 'refs/heads/*' --merged develop/master 

Is this possible?

I could find many solutions, but I don't want to work with cloned repository. I need simply one command which takes repository URL and works.

2

There are 2 answers

2
Timothy Truckle On

the good new is that gitbash also provides some usefull Un*x utilities:

 git branch -r --merged master | grep "origin/" 
8
torek On

This cannot be done without making a clone. It's as simple as that: the hash IDs you get from git ls-remote uniquely identify commits, but unless you have the commits that come before those commits, the only way to tell if some refs/heads/branchname is an ancestor of refs/heads/master is if they have the exact same hash ID. That only suffices for a branch that was just merged.

Note that some servers provide their own (non-Git) interfaces, and at least one of those (GitHub) shows you that some branch is "merged" (and can therefore be deleted). This is not something you can access using git ls-remote.