{"id":728,"date":"2012-07-21T02:10:00","date_gmt":"2012-07-21T02:10:00","guid":{"rendered":"https:\/\/www.keenertech.com\/?p=728"},"modified":"2012-07-21T02:10:00","modified_gmt":"2012-07-21T02:10:00","slug":"viewing-aging-git-branches","status":"publish","type":"post","link":"https:\/\/staging.keenertech.com\/?p=728","title":{"rendered":"Viewing Aging Git Branches"},"content":{"rendered":"\n<p>This really simple shell script from my friend, Robb Kidd, system administrator extraordinaire, shows git branches in order based on their most recent check-in date. You&#8217;d be surprised how useful this script is.<\/p>\n\n\n\n<p>As a developer, you may be working on multiple bug fixes, plus longer-term development tasks, at the same time on a particular project. With git as your source code repository, it&#8217;s common for developers to work on each fix or task in a different branch.<\/p>\n\n\n\n<p>But then you have to remember those branch names, and which branches you worked in most recently.<\/p>\n\n\n\n<p>The&nbsp;<em>aging<\/em>&nbsp;script creates a simple &#8220;report&#8221; showing all branches, in order based on how recently changes have been checked in. It also shows who committed the most recent check-in.<\/p>\n\n\n\n<p>Here&#8217;s the script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\n\ngit branch -a | grep -v HEAD | sed s\/^..\/\/ | while read branch; do\n  echo `git log -1\n    --pretty=format:\"%Cgreen%ci %Creset%h %Cblue%cr%Creset (%cn)\" $branch`\n    $branch ; \ndone | sort\n<\/pre>\n\n\n\n<p>Note that the code has been tidied up for display. The two indented lines after the &#8220;echo&#8221; line should actually be on the same line.<\/p>\n\n\n\n<p>The output looks like this:<\/p>\n\n\n\n<p>2012-07-10 16:37:34 -0400&nbsp;0e3ac28 11 days ago (David Keener) remotes\/origin\/breadcrumbs_fix<br>2012-07-11 11:25:42 -0400&nbsp;57338ee 10 days ago (Chad Fowler) remotes\/origin\/fix_elevated_alarm<br>2012-07-12 13:47:56 -0400&nbsp;c3e3df0 9 days ago (Jim Wierich) remotes\/origin\/disableNegativity<br>2012-07-12 15:25:38 -0400 270537c 9 days ago (Rich Kilmer) remotes\/origin\/updateXMLFile<br>2012-07-12 16:24:39 -0400&nbsp;8ce5787 9 days ago (Yehuda Katz) remotes\/origin\/master<br>2012-07-13 10:28:13 -0400&nbsp;9d56685 8 days ago (Yehuda Katz) remotes\/origin\/dns_error<br>2012-07-13 10:50:02 -0400&nbsp;61525d5 8 days ago (Chad Fowler) remotes\/origin\/XYZ_fix<br>2012-07-16 12:07:39 -0400&nbsp;d835f8d 5 days ago (David Keener) remotes\/origin\/search_widget_upgrade<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This really simple shell script from my friend, Robb Kidd, system administrator extraordinaire, shows git branches in order<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[91,190],"class_list":["post-728","post","type-post","status-publish","format-standard","hentry","category-technology","tag-git","tag-shell"],"_links":{"self":[{"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=\/wp\/v2\/posts\/728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=728"}],"version-history":[{"count":0,"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=\/wp\/v2\/posts\/728\/revisions"}],"wp:attachment":[{"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.keenertech.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}