Find out the creator of the Git branch

I want to know who created the branch.

I'm kind of able to do this with:

git branch -a | xargs -L 1 bash -c 'echo "$1 'git log --pretty=format:"%H %an" $1^..$1'"' _ 

However, this returns the last committer to the branch, and not necessarily the person who created the branch.

+134
git git-branch
Aug 21 2018-12-12T00:
source share
10 answers

A branch is nothing more than a commit pointer. Thus, it does not track metadata like β€œwho created me”. Look at yourself. Try cat .git/refs/heads/<branch> in your repository.

It is written if you are really tracking this information in your repository, check out the branch descriptions. They allow you to attach arbitrary metadata to branches locally on a measure.

Also DarVar's answer below is a very smart way to get this information.

+47
Aug 21 2018-12-12T00:
source share

List Remote Git Branches Author Author sorted by committerdate:

 git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n 
+261
Oct 02 '13 at 11:14
source share

I modified the above answers using the -sort flag and adding some color / formatting.

 git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p) %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes 
+40
Aug 31 '16 at 13:34
source share

Adding to https://stackoverflow.com/a/464632/

 git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n | awk '{print $7 $8}' 

PS We used awk for beautiful printing of the author and the remote branch

+8
Jul 16 '14 at 17:48
source share
 git for-each-ref --format='%(authorname) %09 -%(refname)' | sort 
+8
Jun 29 '16 at 14:48
source share

You can find out who created the branch in the local repository,

 git reflog --format=full 

Output Example:

 commit e1dd940 Reflog: HEAD@{0} (a <a@none>) Reflog message: checkout: moving from master to b2 Author: b <b.none> Commit: b <b.none> (...) 

But this is probably useless, as usual in your local repository, only you create branches.

Information is stored in. /.git/logs/refs/heads/branch. Content example:

 0000000000000000000000000000000000000000 e1dd9409c4ba60c28ad9e7e8a4b4c5ed783ba69b a <a@none> 1438788420 +0200 branch: Created from HEAD 

The last commit in this example was from user "b", and the branch "b2" was created by user "a". If you change your username, you can make sure that git reflog takes information from the log and does not use a local user.

I do not know about the possibility of transferring this local log information to a central repository.

+4
Aug 05 '15 at 15:47
source share

provided:

  • branch
  • was made from master
  • not yet merged with master



  git log --format="%ae %an" master..<HERE_COMES_BRANCH_NAME> | tail -1 
+1
Feb 16 '17 at 18:03
source share

NOTE. This may be a partial answer for you.

For us it was a complete answer.

We need all the branches and their owners to be deleted, since there were only 10 of us, but there were 200 more existing branches. This can be seen from:
https://my-github-domain-name.com/my-git-organization-name/my-git-repo-name/ branches / active

I used the command below while in the local directory of the git repository:

 git branch --list -a > branch-list.txt 

Then all branches fall into the file branch-list.txt.

Since we entered the names in the git branch names, we have already completed.

0
May 13 '17 at 8:31 a.m.
source share

I know that this is not entirely the subject of the question, but if you find it necessary to filter only commits by a specific author, you can always turn to grep :)

 # lists all commits in chronological order that # belong to the github account with # username 'MY_GITHUB_USERNAME' (obviously you # would want to replace that with your github username, # or the username you are trying to filter by) git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -committerdate | grep 'MY_GITHUB_USERNAME' 

Good coding! :)

0
Mar 16 '18 at 22:19
source share

As far as I know, you can see if you are the creator of the branch. This is indicated by the first line in .git / ref / heads / <branch>. If it ends with "Created from HEAD", you are the creator.

-one
Feb 02 '13 at 20:57
source share



All Articles