git branch for multiple remotes -


when running git branch -r see branches on remote repository. there way see in same working directory, branches of multiple repositories? goal create file lists branches in couple of repositories, this:

repo1:master,dev,qa,fy-2473 repo2:master,dev,fy-1128,staging repo3:master,fy-1272,staging 

so on , forth. have print branches right way:

git branch -r | awk -f' +|/' -v ors=, '{if($3!="head") print $3}' >> repolist.txt 

i need have functionality work couple of repositories without having clone each , of them single purpose. thanks.

add repos remotes local repo git remote add, git fetch --all them , adapt awk command produce result want.

this command produce output expect

git branch -r | awk '     # split remote , branch     {         remote = substr($1, 0, index($1, "/") - 1)         branch = substr($1, index($1, "/") + 1)     }      # eliminate head reference     branch == "head" { next }      # new remote found     remote != lastremote {         # output remote name         printf "%s%s:", lastremote ? "\n" : "", remote         lastremote = remote         # not output next comma         firstbranch = 1     }      # output comma between branches     !firstbranch { printf "," }     firstbranch { firstbranch = 0 }      # output branch name     { printf branch }      # final linebreak     end { print "" } ' 

or one-liner without comments

git branch -r | awk '{ remote = substr($1, 0, index($1, "/") - 1); branch = substr($1, index($1, "/") + 1) } branch == "head" { next } remote != lastremote { printf "%s%s:", lastremote ? "\n" : "", remote; lastremote = remote; firstbranch = 1; } !firstbranch { printf "," } firstbranch { firstbranch = 0 } { printf branch } end { print "" }' 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -