When I type git branch, I receive a list of branches that appear to be sorted alphabetically instead of being sorted by their creation time.
Is there a way to make the output of git branch sorted by date?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit: Since Git version 2.19 (late 2018), Git obeys a
branch.sortconfiguration. Since Git version 2.7.0 (early 2016),git branchitself allows sorting, so that you do not have to usegit for-each-refdirectly.Edit
Alas there are apparent problems with the sorting options taken by
git-for-each-ref. Since that command is (obviously) explicitely aimed at showingrefsand accepts the--sortoption, I’m thinking of this as a likely bug[1].Here is the best options I can further come up with, but the output is quite far estranged from the original format (because they rely on decorating revisions after the fact to refer to branches). Ah well, maybe it is of use for you:
[1] if this were
git-rev-listorgit-logI would think the problem would be that we’re not actually walking a revision tree; we’re actively trying to show only tips of trees, without walking them.Temporary alternative
This would give you a list similar to
_As you can see, the result can be a bit overwhelming in the presence of many remote (tracking) branches, which effectively alias the same revisions. However, the result is properly ordered by (descending) date.
The correct (unfortunately broken?) approach…
No, but you should be able to do
(use
--sort='-*authordate'for author date ordering)On my test repo, this yields:
Alias
you can create a git alias to do this: append the following lines to
.git/configFrom then on, you could just say
git branch2