2

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?

SATO Yusuke
  • 1,600
  • 15
  • 39

1 Answers1

2

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:

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I took a brief look at my repository and I found that, in the most branches, the user who added the first commit to an branch was the creator of that branch. How can I list the author of the first commit on each branch, rather than the last one? – SATO Yusuke Dec 13 '17 at 15:21
  • @satob if you need to contact someone, it is best to contact the one who most recently updated the branch. But if you must: https://stackoverflow.com/a/32870852/6309 (CLI solution) or graphql solution (if you don't have a local clone): https://stackoverflow.com/a/47523826/6309 – VonC Dec 13 '17 at 15:28