alias git-hot-refs="git branch --sort=committerdate | tail"
It opens a fuzzy finder window showing the branches you have in the repo, sorted by recency. Also shows the latest committer and the date. Hit enter on the one you want to swap to it.
git config --global tag.sort -creatordate
(`-creatordate` reverses the sort so that the newest come first.)9:55 AM
I have too many git branches and like many people I developed a convoluted script to show me the most recent ones. I ran this command many times a day for years:
function branches {
for k in `git branch | sed "s/^..//"`; do
echo -e `git log --color -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";
done | sort
}
This outputs the date as the first column in the output so that sort works. Turns out with modern git it’s totally unnecessary. Just configure git branch to sort by the last commit date:
git config branch.sort committerdate
You can also supply this on a one-off basis as git branch --sort committerdate.
What else can you sort by? The manual says “The keys supported are the same as those in git-for-each-ref(1).” The manpage for git-for-each-ref lists a ton of fields, including some that don’t make sense to me as sort keys. Here are a few that stood out as interesting:
authordate, committerdate, creatordate, taggerdatecontents:size: The size in bytes of the commit or tag message.push: The name of a local ref which represents the @{push} location for the displayed ref.refname: The name of the ref (the part after $GIT_DIR/) (this is the default).upstream: The name of a local ref which can be considered “upstream” from the displayed ref.Git