15

There was a branch created by a user (knownUserName) in our code repository (repoEx). Where he committed and pushed a few of his changes, but he didn't create a pull request for the same.

It has been long and there is an exponential increase in the number of branches that the repository now has because of which we are unable to go through all the branches and find the one created by him.

Is there a way to search all the branches using the git command line or GitHub interface, to find all the branches created by a user in a specific repository?

I tried using the GitHub interface and filtering the branches (under https://github.com/repoEx/branches/all) using the search parameter as -

author:<knownUserName>

but this won't work. The search seems to be effective with a branch name, but I don't have any clue about the name.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Naman
  • 27,789
  • 26
  • 218
  • 353
  • You can get list of unmerged branch `git branch --no-merged` – Ôrel Dec 13 '16 at 07:14
  • @Ôrel I guess that is returning list of those branches that I have created and are not yet merged. – Naman Dec 13 '16 at 07:17
  • For me there is no branch creator, you just know author and submitter of commit, once you have the branch list, if it is a very long list, you can get author of the last commit of each branch to find the branch – Ôrel Dec 13 '16 at 07:35
  • @Ôrel Okay, in the current case, the creator, author and submitter is the same `knownUserName` and the suggested answer is still not working if I run it using bash. – Naman Dec 13 '16 at 08:36
  • 3
    branch is not an entity on git which contains an creator. a Branch is just a sequence of commits and a name basically – pedrorijo91 Dec 13 '16 at 10:14
  • @pedrorijo91 I understand that fact, but then with the only information being the username, I would eventually want to move in the direction of finding the branch(specific sequence of commits) which has the required commits from the user. – Naman Dec 13 '16 at 10:16

3 Answers3

11

This is for OS X. Just adding grep on to this answer here and modifying for email, you get

git for-each-ref --format='%(committerdate) %09 %(authoremail) %09 %(refname)' | sort -k5n -k2M -k3n -k4n | grep <author-email>

which works quite well.

[Other answer did not work for me, not sure why]

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
5

Loop on the branch, display the last commit information, and grep on the username.

You will have the commit id you are looking for:

for co in `git branch -a --no-merge`; do  git log -1 --no-walk --pretty=format:"%h - %an, %ar : %s" $co; done | grep <knownUserName>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ôrel
  • 7,044
  • 3
  • 27
  • 46
-4

CLick on branches and after that you will see an option saying your branches Click here to see the image!