Some Git Branch Stuff
Elyees T.
Posted on February 26, 2024
This is pretty minor, but one thing that’s always bugged me about Git is that I run git branch a lot to view what branches I have, but they’re in the dumbest possible order (alphabetic) and there are a million of them after a while.
At some point I started naming my branches in a way to partially cope with this. Every branch would be something like sc-0831-my-thing meaning that the branch topic was “my thing”, it was created on August 31st and the sc are my initials so I can group them by whose branch. It’s a lot of stupid metadata to try to cram into a branch name just because of how it’s listed.
However, now we can ask Git to do two things that help with this. We can ask it to sort by objectsize, authordate, committerdate, creatordate, or taggerdate with the --sort option and we can set it as a default with the branch.sort config setting.
So for example, if I want to sort by last commit date descending, I can run:
$ git config --global branch.sort -committerdate
And now the default will show the branch that I last committed to at the top.
💡 Important note: the -committerdate has a leading - but not a double dash. It’s just a negative. I’ve seen people mess this up and then things break.
However, now if I have a bunch of branches, that will scroll off the screen. Sad. But now Git also has a way to take a list of branches and try to split it into columns to make better use of the screen real estate. You can do this either with the new --column
option, or with the column.ui
setting.
Check it out:
As another sort of funny thing, in order to help with this, Git implemented it’s own list to column terminal command that is sort of completely independent of anything else in Git and is it’s own command called git column
.
Just in case there is anything else you need to convert into columns that isn’t Git related.
Posted on February 26, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.