Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Last active March 15, 2020 11:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JamieMason/7357169 to your computer and use it in GitHub Desktop.
Save JamieMason/7357169 to your computer and use it in GitHub Desktop.
List all remote branches, most recent first
for branch in `git branch -r | grep -v HEAD`; do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r
@JamieMason
Copy link
Author

Example output.

The %ci format is a little ugly (outputting 2013-11-06 22:31:56 +0000) but it's needed to be able to sort the results by most recent commit.

2013-11-06 22:31:56 +0000 18 hours ago  origin/refactor
2013-10-24 13:24:40 +0100 2 weeks ago   origin/issue-52
2013-10-24 11:13:56 +0100 2 weeks ago   origin/issue-51
2013-10-14 11:07:05 +0100 3 weeks ago   origin/gh-pages
2013-09-29 20:50:54 +0100 6 weeks ago   origin/develop
2013-08-10 19:01:08 +0100 3 months ago  origin/jamesstout-issue-41
2013-08-10 17:16:36 +0100 3 months ago  origin/jamesstout-issue-40
2013-08-10 16:01:20 +0100 3 months ago  origin/master
2013-06-23 22:33:30 +0100 5 months ago  origin/issue-7
2013-03-04 11:23:29 +0000 8 months ago  origin/headless

@JamieMason
Copy link
Author

With author name

for branch in `git branch -r | grep -v HEAD`; do echo -e `git show --format="%ci %an %cr" $branch | head -n 1` \\t$branch; done | sort -r

Example output.

2013-11-06 22:31:56 +0000 Jamie Mason 18 hours ago  origin/refactor
2013-10-24 13:24:40 +0100 Jamie Mason 2 weeks ago   origin/issue-52
2013-10-24 11:13:56 +0100 Jamie Mason 2 weeks ago   origin/issue-51
2013-10-14 11:07:05 +0100 Jamie Mason 3 weeks ago   origin/gh-pages
2013-09-29 20:50:54 +0100 Jamie Mason 6 weeks ago   origin/develop
2013-08-10 19:01:08 +0100 Jamie Mason 3 months ago  origin/jamesstout-issue-41
2013-08-10 17:16:36 +0100 Jamie Mason 3 months ago  origin/jamesstout-issue-40
2013-08-10 16:01:20 +0100 Jamie Mason 3 months ago  origin/master
2013-06-23 22:33:30 +0100 Jamie Mason 5 months ago  origin/issue-7
2013-03-04 11:23:29 +0000 Jamie Mason 8 months ago  origin/headless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment