Is it possible to get a list of merges into a branch from the Github website OR API?

In our workflow, no "direct" commits are made into the master branch. The master branch only receives merges from Pull Requests.

We can think of each merge then as a new feature added to the master branch.

So I'd like to get a list of merges into master, as a way to visualize the blocks of features added into the product over time.

Does git or the Github API expose this query, or do I have to parse raw commits?


I use the following script:

git log --merges --first-parent master \
        --pretty=format:"%h %<(10,trunc)%aN %C(white)%<(15)%ar%Creset %C(red bold)%<(15)%D%Creset %s"

Explaining each argument:

  • --merges: only "merge" commits (more than 1 parent);
  • --first-parent master: only merges applied to master. This removes the entries where someone merged master into their branches;
  • --pretty-format: applies the following formatting:
    • %h: the commit short hash;
    • %<(10,trunc)%aN: author name, truncated at 10 chars;
    • %<(15)%ar: the relative commit time, padded to 15 chars;
    • %<(15)%D: the tag names, also padded to 15 chars;
    • %s: first line of the commit message.

The result is pretty satisfying:

terminal image of the command output


Git exposes such feature through the git log command. This command accepts some switches that filter the rendered commits according to the number of parents commits.

One of them would fit your request:

  • --merges Print only merge commits. This is exactly the same as --min-parents=2.

The following shows the merge commits (ie. commits with more than one parent) reachable from the vNext branch of the LibGit2Sharp project

$ git log vNext --merges --oneline
090b2de Merge pull request #348 from jamill/credential_callback_fix
0332c35 Merge pull request #260 from ben/great-renaming
3191c1b Merge pull request #239 from ben/libgit2-upgrade-81eecc3
1d544e8 Merge branch 'vNext'
238d259 Merge remote-tracking branch 'origin/master'

Update

Leveraging the same output through the GitHub API is possible, but would be somewhat more complex.

This would require to retrieve all the commits from a branch, paginating through all the results (in order to retrieve all the commits meta data) while filtering out the ones that only expose only one parent node.

As a starting point, the following url shows the latest 30 commmits of the vNext branch.

  • https://api.github.com/repos/libgit2/libgit2sharp/commits?sha=vNext