Ofir Farchy
Ofir Farchy

Reputation: 8037

Find out a Git branch creator

I want to find out who created a branch.

I am sort of able to do so 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 per branch, not necessarily the person who created the branch.

Upvotes: 241

Views: 236784

Answers (15)

Leponzo
Leponzo

Reputation: 657

Bitbucket shows it to repository administrators under Repository settings > Push Log. See https://confluence.atlassian.com/bitbucketserver/push-logs-998882984.html.

Upvotes: 1

Andrii Vakariuk
Andrii Vakariuk

Reputation: 1

Just try to find a first commit. Checkout to the target branch and run

git log --reverse

Upvotes: 0

P-L
P-L

Reputation: 533

If you are using Azure Devops, it is possible to retrieve this information using the REST API :

$baseAzdoURI/_apis/git/repositories/$repositoryName/refs

Inside the returned json array, the creator name will be inside the [collectionElement].Creator.DisplayName

ex.

        {
        "name": "refs/heads/branchname",
        "objectId": "GUID",
        "creator": {
            "displayName": **"John Deere"**,
            "url": "$baseAzdoURI/_apis/Identities/GUID",
            "_links": {
                "avatar": {
                    "href": "$baseAzdoURI/_apis/GraphProfile/MemberAvatars/BASE64STUFF"
                }
            },
            "id": "guid",
            "uniqueName": "DOMAIN\\USERNAME",
            "imageUrl": "$baseAzdoURI/_api/_common/identityImage?id=guid",
            "descriptor": "BASE64STUFF"
        },
        "url": "$baseAzdoURI/GUID/_apis/git/repositories/GUID/refs?filter=heads%2FBRANCHNAME"
    },

ref: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/refs/list?view=azure-devops-rest-7.0

Upvotes: 1

Viker
Viker

Reputation: 3243

Warning!

Note that these commands show the commit data where the branch is pointing, and so the commit author, that could be different than the branch author. Git doesn't store the branch creator, just the commit's one.

Upvotes: 1

tech2504
tech2504

Reputation: 977

We can find out based upon authorname

git for-each-ref --format='%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)' refs/remotes/ --sort=authorname DESC

Upvotes: 6

DarVar
DarVar

Reputation: 18124

List remote Git branches by author sorted by committer date:

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate

Upvotes: 399

rob bee
rob bee

Reputation: 1

for those looking for a DESC ... this seems to work --sort=-

ty for the formatting, new to this ...my eyes are loosing some of it's bloodshot

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

further ref: https://stackoverflow.com/a/5188364/10643471

Upvotes: 0

Trident D'Gao
Trident D'Gao

Reputation: 19690

Assuming:

  1. branch was made from master
  2. hasn't been merged to master yet

 git log --format="%ae %an" master..<HERE_COMES_THE_BRANCH_NAME> | tail -1

Upvotes: 6

Mike
Mike

Reputation: 1634

I tweaked the previous answers by using the --sort flag and added 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

Upvotes: 70

suryakrupa
suryakrupa

Reputation: 4112

Adding to DarVar's answer:

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

P.S.: We used AWK to pretty print the author and the remote branch.

Upvotes: 10

avocadojesus
avocadojesus

Reputation: 231

I know this is not entirely the scope of the question, but if you find the need to filter only commits by a specific author, you can always pipe 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'

happy coding! :)

Upvotes: 1

KhaledMohamedP
KhaledMohamedP

Reputation: 5532

git for-each-ref --format='%(authorname) %09 -%(refname)' | sort

Upvotes: 12

Gustave
Gustave

Reputation: 3528

You can find out who created a branch in your local repository by

git reflog --format=full

Example output:

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 typically on your local repository only you create branches.

The information is stored at ./.git/logs/refs/heads/branch. Example content:

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

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

I don't know about any possibility to transmit that local log information to a central repository.

Upvotes: 8

Christopher
Christopher

Reputation: 44234

A branch is nothing but a commit pointer. As such, it doesn't track metadata like "who created me." See for yourself. Try cat .git/refs/heads/<branch> in your repository.

That written, if you're really into tracking this information in your repository, check out branch descriptions. They allow you to attach arbitrary metadata to branches, locally at least.

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

Upvotes: 87

Kendor
Kendor

Reputation: 11

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

Upvotes: 0

Related Questions