Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the user who created a branch with GitHub API

Background

  • I am using GitHub Enterprise. I want to check unused branches in my repository, and ask owners of these unused branches to clean-up.
  • You can see "Your branches" (branches created by current user) on “Branches” page in GitHub. So I think GitHub might have information for who created a branch.
  • On the other hand, the result of GitHub REST API (https://developer.github.com/v3/git/refs/#get-a-reference) does not contain the creator of the specified branch.

Question

Is there’s any way to get the user who created a branch with GitHub API?

like image 768
SATO Yusuke Avatar asked Mar 27 '26 21:03

SATO Yusuke


1 Answers

There is no real "ownership" associated to a branch with Git/GitHub.
As mentioned in the documentation, "Your branches" reference in a repository the branches you have push access to, not necessarily the ones you have "created".

https://help.github.com/assets/images/help/branches/branches-overview-atom.png

The best you can do is, if you have access to a local clone, a simple git fetch, followed by:

git for-each-ref --format="%(committerdate) %09 %(refname:short) %09 %(authorname)" --sort=-committerdate refs/remotes/origin

That will list the remote branches from the most recent updated one to the oldest, with the author of the last commit on each branch.

But if you have to use GitHub API, then you would need to:

  • list the remote branches,
  • then for each one get the commit mentioned with the branch

You can then contact the committer of that most recent commit.

like image 133
VonC Avatar answered Mar 29 '26 23:03

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!