Wednesday, February 14, 2018

Git 'r Done

Wow, it's already far into the new year, and I've not written anything since before the winter (at least in my hemisphere) holidays. Time marches on, though, so this is a short post that maybe will make things a little easier.

One of the things I've come to rely on is the ubiquity of git. Seems like nearly every company is using it, whether it's github, or some internally hosted version...or even something, like Bitbucket, that uses git as its engine.

There are a lot of arguments about how best to use git - some people (*cough* wrongly *cough*) suggest that all development ought to be done in a fork and merged back into the communal repo and some use a clone/branch model. One argument against the clone/branch model is the number of branches that become stale - and frankly, it can become a mess.

One thing you, as a maintainer, will need to do if you're using a clone/branch model is establish, fairly early, a process for pruning those stale or dead branches. Once you have a process in place, though, what do you do? How do you list the branches and their detail in a convenient way?

One way is the following...

git for-each-ref --sort=authordate --format='%(authordate:iso8601) %(refname) by %(authoremail)' refs/remotes

This will give a list that can be used to either manually delete branches, or you could use this within a script that takes some action, like emailing or deleting, when the ref matches some criteria. Here's some sample data in case you want to build such a tool.

2017-07-27 22:29:31 -0400 refs/remotes/origin/master by <hrobertking@mailinator.com>
2017-10-03 11:31:58 -0700 refs/remotes/origin/lint-config by <hrobertking@mailinator.com>
2017-11-01 11:15:33 -0700 refs/remotes/origin/feature/US123456789 by <james.howlett@mailinator.com>
2018-01-10 14:26:58 -0700 refs/remotes/origin/feature/US234567890 by <james.howlett@mailinator.com>
2018-01-23 15:51:15 -0700 refs/remotes/origin/bugfix/DE123456 by <ororo.munroe@mailinator.com>
2018-01-25 16:51:50 -0700 refs/remotes/origin/bugfix/DE234567 by <remy.lebeau@mailinator.com>
2018-01-30 12:00:58 -0500 refs/remotes/origin/bugfix/DE345678 by <ororo.munroe@mailinator.com>
2018-01-31 17:47:52 -0500 refs/remotes/origin/feature/US345678901 by <hrobertking@mailinator.com>
2018-02-02 14:36:42 -0700 refs/remotes/origin/bugfix/DE456789 by <hrobertkinging@mailinator.com>

If you're looking for other git things to do, feel free to check out my github git repo, where you'll find a sample .gitconfig with aliases that have been tested in the bash terminal on a Mac. Most also run on PuTTY or other clients that can run a bash session, but a few will need to be modified.

Hopefully, this will help you "git 'r done" (after thinking about what you need to do, of course).

Happy coding.

No comments:

Post a Comment