Sections of orders in `git branch --all` by branch name
I have a repository with multiple remotes. When I issue git branch --all --verbose
it shows:
bar 9876de11 hello world
foo 12abde23 description
master 34fd4545 tony the pony
quz ab34df67 me, too
remotes/origin/bar 9876de11 hello world
remotes/origin/foo 12abde23 description
remotes/origin/master 34fd4545 tony the pony
remotes/origin/quz ab34df67 me, too
remotes/zulu/bar 9876de11 hello world
remotes/zulu/foo 12abde23 description
remotes/zulu/master 34fd4545 tony the pony
remotes/zulu/quz ab34df67 me, too
In this output, it is difficult to see if each local branch is on par with its remote counterparts. I would like the result to be ordered with a local name:
bar 9876de11 hello world
remotes/origin/bar 9876de11 hello world
remotes/zulu/bar 9876de11 hello world
foo 12abde23 description
remotes/origin/foo 12abde23 description
remotes/zulu/foo 12abde23 description
master 34fd4545 tony the pony
remotes/origin/master 34fd4545 tony the pony
remotes/zulu/master 34fd4545 tony the pony
quz ab34df67 me, too
remotes/origin/quz ab34df67 me, too
remotes/zulu/quz ab34df67 me, too
Thus, antialiasing on the output to see unpushed changes would be much easier on the eye. Naive solution
git branch -a -v | sort -t / -k 3
doesn't work because local entries don't have "/" in them sort
to look for.
source to share
It might be a little rough, but try this:
git branch --all --verbose | sed 's/^[ *] //' | while read line; do echo $(basename $(echo $line | awk '{ print $1 }')) $line; done | sort | cut -d' ' -f2-
Basically, we are basename
fetching branches, giving us only branchname without remotes/origin/whatever
. Then we sort it and then we wrap up the final output through cut
. This can be changed and cleaned up, but it should give you a starting point. You can also add --color
to initial git branch
to keep the colored output you see without piping git
.
source to share