Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - list remote branches with their author names

Tags:

git

cmd

Based on my search , the below 2 commands are supposed to give me remote branches with their author name. However, I get nothing in return - do you know why ?

I am using windows command prompt.

The below command returns : "Input file specified two times."

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n

The below command returns nothing :

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

What should I do to list all active branches with their author names ?

like image 755
Pratap Das Avatar asked Oct 29 '18 18:10

Pratap Das


2 Answers

You are trying to run a Unix-Command in a Windows cmd shell. The Windows sort does not understand the -k5n syntax. Try running it in the bash shell provided by Git For Windows and it will not print errors.

There is room for improvement though: git for-each-ref can sort itself:

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

Next: You mentioned you want only remote branches. Actually you also get local branches, tags, notes and perhaps some more stuff. You can restrict it to remote branches:

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

Since there is no sort command any more you can run it in cmd again after adjusting the quoting of the format parameter (cmd and bash use different quoting semantics):

git for-each-ref --sort=committerdate --format="%(committerdate) %09 %(authorname) %09 %(refname)" refs/remotes
like image 178
A.H. Avatar answered Nov 28 '22 13:11

A.H.


You should try to put double quotes instead of simple :

git for-each-ref --format="%(committerdate) %09 %(authorname) %09 %(refname)" | sort -k5n -k2M -k3n -k4n

If it doesn't work, just try without the sort causing the error :

git for-each-ref --format="%(committerdate) %09 %(authorname) %09 %(refname)"
like image 31
André DS Avatar answered Nov 28 '22 13:11

André DS