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

I use the following script:

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

Explaining each argument:

  • main: the name of your main branch. Can be omitted, in which case the current branch will be used.
  • --first-parent: skips commits from merged branches. This removes the entries where someone merged master into their branches.
  • --merges: shows only “merge commits” (commits with more than 1 parent). Omit this argument if you want to see direct commits to your main branch.
  • --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

Leave a Comment