Skip to content

Instantly share code, notes, and snippets.

@christineyen
Last active February 3, 2023 21:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christineyen/9202388 to your computer and use it in GitHub Desktop.
Save christineyen/9202388 to your computer and use it in GitHub Desktop.
Longer-lived feature branches can usually benefit from notes, so you can figure out more quickly where you were at in the process. TIL about branch descriptions, and made it easier to keep track of my various branches.
sample output: branch names have been changed to protect the innocent
cyen:~/working-path (christine.maybe-whipped-cream)$ git branchdate
2 hours ago master
2 hours ago christine.maybe-whipped-cream
3 hours ago christine.magic-shell -- make sure to use the stuff that hardens, not just choc syrup
10 days ago christine.maybe-add-caramel-syrup
4 weeks ago christine.serve-in-cream-puff -- WIP; current implementation looks too small
5 months ago christine.cream-puff-proof-of-concept
You lose the * marking which branch you're on, but I have the current branch displayed in my prompt anyway, so don't need it.
In this most recent revision, I colorize the left-hand column by age of branch: faintly green for branches updated hours ago, faintly yellow for branches updated days ago, and faintly red otherwise. Colors are removable (remove lines 10-17 and replace the second argument to printf with a simple $authordate) or tweakable (run the for loop at the bottom of expanded-branchdate-scripts.sh and replace the numbers as appropriate) to your heart's content.
git for-each-ref --sort='-authordate' --format='authordate="%(authordate:relative)";ref=%(refname:short)' refs/heads | \
while read entry;
do
eval $entry;
desc=`git config branch.$ref.description`;
if [ -n "$desc" ];
then
desc="\t\t\t\t-- $desc";
fi;
i=181 # colorize my timestamps!
if [[ $authordate == *second* ]]
then
i=81
elif [[ $authordate == *minute* ]]
then
i=152
elif [[ $authordate == *hour* ]]
then
i=150
elif [[ $authordate == *day* ]]
then
i=229
fi
printf "%s " "$(tput setaf $i)$authordate$(tput sgr0)";
printf '\t%-50s' $ref;
echo $desc;
done
# customize your colors!
for row in $(seq 1 15); do for col in $(seq 0 16); do i=$((row+15*col)); printf "$(tput setaf $i)##% -4d ## " $i; done; echo ""; done; echo ""
; other stuff
[alias]
branchdate = "!git for-each-ref --sort='-authordate' --format='authordate=\"%(authordate:relative)\";ref=%(refname:short)' refs/heads | while read entry; do eval $entry; desc=`git config branch.$ref.description`; if [ -n \"$desc\" ]; then desc=\"\t\t\t\t-- $desc\"; fi; i=181; if [[ $authordate == *hour* ]]; then i=150; elif [[ $authordate == *day* ]]; then i=229; fi; printf \"%s \" \"$(tput setaf $i)$authordate$(tput sgr0)\"; printf '\t%-50s' $ref; echo $desc; done"
branchedit="branch --edit-description"
@sebastian
Copy link

Thanks @christineyen, these were very useful!

@gasi
Copy link

gasi commented Feb 25, 2014

👍

@maplebed
Copy link

maplebed commented May 2, 2014

I love it! Definite improvement over just 'git branch'. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment