for k in
git branch | perl -pe s/^..//; do echo -e
git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1\\t$k; done | sort -r
The set of piped commands above produces easy-to-read output of all your repo’s branch names and their last commit dates.
Below is an explanation of the commands:
for k instarting of a command line loop
git branchlist all branches in repo one at a time. Through the loop the current branch name is set to k
| perl -pe s/^..//`;pipe the git branch output to perl which performs a regular expression (
-eflag ) removing spaces on each line of output (
-p) flag, so just the branch name is set to k without spaces or return characters.
do echo -eprint to the screen every item in the for k loop
git showshows the change date as well as the changes of the k branch. Adding the
pretty=format:allows the default date structure to be changed and coloured, making the output more legible and informative. You can read more about pretty=format: here.
-- | head -n 1pipes the git show output into the head command, which just returns the first line;
-n 1ensures only the first line is shown.
\\t$kprints a tab and then writes the k value, which is the name of the branch.
; doneends the looping.
| sort -rpipes the final looped output to the sort command. Sort command is somewhat magical, as it is able to deduce the beginning of each output line is a date and sort by that date. The
-rflag reverses the output, making the newest branch commit date at the top.