Tony Scialo
Tony Scialo

Reputation: 5957

Git - View Remote branches by creation date

Is it possible to see the list of remote branches by creation date instead of alphabetical order?

Right now i use

git branch -r

Which outputs the below list of remote branches:

 origin/HEAD -> origin/develop
 origin/calendar-view-impl
 origin/containers-redesign
 origin/develop
 origin/dialogs-view-impl
 origin/dropdowns-redesign

It would be nice if this could be ordered by CREATION date of the branch.

Upvotes: 23

Views: 13390

Answers (2)

Robin Bastiaan
Robin Bastiaan

Reputation: 702

Building upon the answer given by @sachin-thapa, I have come to the following answer:

git for-each-ref --sort=-authordate | grep 'refs/remotes/origin/' -m 10

This will:

  • List only remote branches.
  • Sort them by authordate, most recently changed branch on top.
  • Limits the result to only 10 results to not get lost in a wall of results.

Now, going the extra mile, you can make an alias for this like below, to make it possible to retrieve this list by just typing git recent.

git config --global alias.recent '!git for-each-ref --sort=-authordate | grep "refs/remotes/origin/" -m 10'

Upvotes: 2

Sachin Thapa
Sachin Thapa

Reputation: 3719

There is a field in git called authordate which can help to achieve similar result, please try following:

git for-each-ref --sort='-authordate'

Hoping this helps.

Cheers !

Upvotes: 29

Related Questions