Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a branch has been merged into master using github api (or octokit)

I'd like to check if a feature branch has been merged into my master branch using the github api/Octokit. I havent been able to find any documentation or posts on this topic. Is this possible? Does anyone know of any posts that address this topic?

like image 701
Billy Avatar asked Oct 26 '15 14:10

Billy


People also ask

How can you tell if two branches are merged?

Suppose you are on branch master and you want to check if the git merge origin/devel will work. Then just do: git merge-tree `git merge-base origin/devel master` master origin/devel . But this one line is way more powerful than it looks, because you can also do this on a branch that is not checked out.

What is OctoKit?

objc. OctoKit has been extracted from GitHub for Mac by the Mac team and is a Cocoa and Cocoa Touch framework for interacting with the GitHub API, built using AFNetworking, Mantle, and ReactiveCocoa.


1 Answers

This is the equivalent to git log master..my-cool-branch using Octokit - you want to see if there are any commits on your branch which are not in master:

var head = "my-cool-branch";
var baseBranch = "master";
var compareBaseToHead = await client.Repository.Commit.Compare(owner, repo, baseBranch, head);

if (compareBaseToHead.TotalCommits == 0)
{
    Console.WriteLine("Branch {0} has been merged into {1}", head, baseBranch);
}
else
{
    Console.WriteLine("Branch {0} has NOT been merged into {1}", head, baseBranch);
}
like image 114
Brendan Forster Avatar answered Oct 28 '22 12:10

Brendan Forster