0 votes
1 view
in Devops and Agile by (20k points)

I want to get a list of all the branches in a Git repository with the "freshest" branches at the top, where the "freshest" branch is the one that's been committed to most recently (and is, therefore, more likely to be one I want to pay attention to).

Is there a way I can use Git to either (a) sort the list of branches by latest commit, or (b) get a list of branches together with each one's last-commit date, in some kind of machine-readable format?

Worst case, I could always run git branch to get a list of all the branches, parse its output, and then git log -n 1 branchname --format=format:%ci for each one, to get each branch's commit date. But this will run on a Windows box where spinning up a new process is relatively expensive, so launching the Git executable once per branch could get slow if there are a lot of branches. Is there a way to do all this with a single command?

1 Answer

0 votes
by (28.4k points)

Use the following command: 

$ git branch --sort=-committerdate

Alternatively, use the following command to do the same:

$ git config branch.sort -committerdate

Whenever you list branches in the current repository, it will be a sorted list based on the 'committerdate'.

In other cases, if you list branches and want them sorted by comitterdate:

$ git config --global branch.sort -committerdate

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...