Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a script to list git branches created by me?

I'm aware that branches don't really store creator information - and they're just a pointer to a commit.

My goal is to be able to clean out my old branches that have been merged back to the main branch, and list branches where this hasn't been done either. (A clean up).

This is different to "finding unmerged branches" because I want to find merged branches as well, and I want to do it by author.

My question is: Is there a script to list git branches created by me?

like image 646
hawkeye Avatar asked Mar 16 '16 03:03

hawkeye


People also ask

How do you find out who created a git branch?

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.

Which git command lists the branches in your repository?

You can list the remote branches associated with a repository using the git branch -r, the git branch -a command or the git remote show command. To see local branches, use the git branch command.


1 Answers

This command lists all branches and their author names

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

If you are using github you can also visit https://github.com/author/repo/branches/yours to get all your branches

If you want to just delete all the already merged branches you can us the command

git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -d 

For more details of git for-each-ref visit here.

like image 194
SachinSunny Avatar answered Oct 01 '22 22:10

SachinSunny