Skip to content

Instantly share code, notes, and snippets.

@JoeGermuska
Created September 10, 2020 22:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeGermuska/c59fd6a610122b36e0b62217ef6d1300 to your computer and use it in GitHub Desktop.
Save JoeGermuska/c59fd6a610122b36e0b62217ef6d1300 to your computer and use it in GitHub Desktop.
Get last commit dates for remote git branches

I had a repo with dozens of abandoned or merged remote branches. Before deleting them wholesale, I wanted to know just how old they were.

I adapted this Stack Overflow answer, but dressed it up in a for loop since I wanted all of them. Also, since I wanted to sort them, I switched the date format to %cs (Short ISO), which didn't work in git 2.18.0 but does work in 2.28.0

for i in `git branch -r|grep -v HEAD` ; do echo `git log -1 --format=%cs $i ` $i; done | sort -r
@JoeGermuska
Copy link
Author

For local, different thing to grep out of the results:

for i in `git branch | grep -v master`;  do  echo  `git log -1 --format=%cs  $i` $i; done

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