{"id":911,"date":"2014-02-13T13:42:12","date_gmt":"2014-02-13T20:42:12","guid":{"rendered":"http:\/\/10kdev.net\/?p=911"},"modified":"2014-02-13T13:43:38","modified_gmt":"2014-02-13T20:43:38","slug":"git-a-developers-workflow","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=911","title":{"rendered":"Git &#8211; A Developer&#8217;s Workflow"},"content":{"rendered":"<p>A few weeks ago I attended a nice little presentation about GIT at our local Chippewa Valley Developers Group meeting. After the show, and discussing the presentation over a couple of brews with a configuration manager and a low level C++ engineer &#8212; we thought that a lot of things weren&#8217;t clear like release strategy.<\/p>\n<p>I remember when Subversion came out, I was really keen on it because it had a very loose workflow, easily adaptable to many technical processes. In fact if you&#8217;ve ever kan-banned, the board *really* starts to look like a release process especially if there are different server environments for say Java web apps. Won&#8217;t get into just how bad those environment columns can get &#8211; I&#8217;ve even seen a board with at least 20 columns of tasks taking up an entire 10X20 ft. wall! A wee bit too much. Git is also loose in this manner, and in my use of Git &#8212; I have more experience in Hg and Darcs &#8212; and talking with a lot of different points of view I think a pattern emereged that is a great practice for developers.<\/p>\n<div style=\"width: 170px\" class=\"wp-caption alignleft\"><img decoding=\"async\" loading=\"lazy\" alt=\"\" src=\"http:\/\/gunsmokenet.com\/GunsmokeTGAW\/Marks-Stuff\/Gunsmoke\/festus.jpg\" width=\"160\" height=\"205\" \/><p class=\"wp-caption-text\">Festus says &#8212; &#8220;Why don&#8217;t you just go on an Git?&#8221;<\/p><\/div>\n<p>Here are the two revelations about Git I&#8217;ve arrived at:<\/p>\n<ol>\n<li>A merge is not a merge is not a merge. That means, merging master and origin (possibly the remote repo, from where you cloned) is NOT the same as merging master and branch. Not at all.<\/li>\n<li>\u00a0A Developer should ALWAYS develop from a branch. Always.<\/li>\n<\/ol>\n<p>The first revelation led to the second revelation. But for some reason, in the merge\/rebase wars &#8212; it was forgotten that a loca branch\/master merge was quite differnt than a master\/origin merge.<\/p>\n<p>The question that led me to this was, I thought you applied a typical master\/origin workflow to a branch. That is, that the realtionship between branch and master was the same as master and origin, such that in branch you would pull &#8211;rebase to sync up with master. Not so. There is no pull activity, unless you wish the branch to pull from origin.<\/p>\n<p>The second question was, discussing with the config manager &#8212; how to bundle features in such a way that it&#8217;s useful to them. It&#8217;s a matter of &#8220;repository scope.&#8221; So this came out of that discussion:<\/p>\n<ol>\n<li>Developers should check in early and often with atomic commits.<\/li>\n<li>Atomic commits are almost useless to a release manager, they want a feature release. SO they need bigger units of commit because they may want to revert that entire feature, and a set of commits won&#8217;t do.<\/li>\n<\/ol>\n<p>Hence, the branch\/master merge creates that package whilst retaining those atomic commits.<\/p>\n<p>For the my developers my workflow is now this when I am assigned work, for a branch named topic:<\/p>\n<p style=\"padding-left: 30px;\"><code>git checkout -b topic<\/code><\/p>\n<p style=\"padding-left: 30px;\"><em>do a bunch of work . . . .<\/em><\/p>\n<p style=\"padding-left: 30px;\"><code>git commit -m \"topic commit 1\"<\/code><\/p>\n<p style=\"padding-left: 30px;\"><code>git commit -m \"topic commit 2\"<\/code><\/p>\n<p style=\"padding-left: 30px;\"><em>now update master from origin . . . .<\/em><\/p>\n<p style=\"padding-left: 30px;\"><code>git checkout master<\/code><br \/>\n<code>git pull --rebase<\/code><\/p>\n<p style=\"padding-left: 30px;\"><em>sync my branch to master. . .<\/em><\/p>\n<p style=\"padding-left: 30px;\"><code>git checkout topic<\/code><br \/>\n<code>git rebase master<\/code><\/p>\n<p style=\"padding-left: 30px;\"><em>merge into master . . .<\/em><\/p>\n<p style=\"padding-left: 30px;\"><code>git checkout master<\/code><br \/>\n<code>git merge topic<\/code><\/p>\n<p style=\"padding-left: 30px;\"><em>and (after checking for changes) push . . .<\/em><\/p>\n<p style=\"padding-left: 30px;\"><code>git push<\/code><\/p>\n<p>Onto solving the second part, making commit&#8217;s for a config manager.<\/p>\n<p>Note that Git implicitely does a &#8220;fast forward&#8221; merge for master\/branch that plays my commits on top of the master, but there&#8217;s never a record of the merge. IN a lot of cases this might be OK, but in many cases we may want a *real* feature branch to retain its unit of checkin. For instance, say the branch was a whole new package, in which case for the config manager we want to do a non-fast forward merge that will remember the commits, but also retain the branch information.<\/p>\n<p style=\"padding-left: 30px;\"><code>git merge --no-ff topic<\/code><\/p>\n<p>Some utilities like &#8220;squash&#8221; seem like a bad choice for this because they toss the history out &#8212; bad for the developer. But this no fast forward merge can do the trick; retain history in all scopes.<\/p>\n<div style=\"width: 473px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" loading=\"lazy\" alt=\"alt text\" src=\"http:\/\/i.stack.imgur.com\/vRdkr.png\" width=\"463\" height=\"414\" \/><p class=\"wp-caption-text\">(From nvie.com, Vincent Driessen, post &#8220;<a href=\"http:\/\/nvie.com\/posts\/a-successful-git-branching-model\/\">A successful Git branching model<\/a>&#8220;)<\/p><\/div>\n<p>The impact of doing development like this is far reaching. For the last years I have been on Subversion checking directly into trunk; and Hg managed a lot of merge and commit history with less work than Git. But the Git community has brought it to my attention &#8212; ALWAYS CREATE A BRANCH before you develop.<\/p>\n<p>I wonder how this will impact code writing. Making a feature being aware that it should be able to be reverted when you check it in is WAY different than checking in non-accessible work-in-progress or hard coding out features.<\/p>\n<p>My personal feeling is that to some extent this is a pipe dream. Many projects have some developers changing underlaying libraries while the rest build on top of them &#8212; the unit of a &#8220;feature&#8221; does not sit at the checkin level. So more hands on and use cases are needed to improve what we do, no doubt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I attended a nice little presentation about GIT at our local Chippewa Valley Developers Group meeting. After the show, and discussing the presentation over a couple of brews with a configuration manager and a low level C++ engineer &#8212; we thought that a lot of things weren&#8217;t clear like release strategy. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/911"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=911"}],"version-history":[{"count":9,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/911\/revisions"}],"predecessor-version":[{"id":920,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/911\/revisions\/920"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=911"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}