{"id":24216,"date":"2015-07-28T23:55:16","date_gmt":"2015-07-28T18:25:16","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=24216"},"modified":"2015-07-29T19:52:49","modified_gmt":"2015-07-29T14:22:49","slug":"git-branch-per-feature-avoid-repeated-sync-of-feature-branch-using-git-rerere","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/git-branch-per-feature-avoid-repeated-sync-of-feature-branch-using-git-rerere\/","title":{"rendered":"Git Branch Per Feature : Avoid repeated sync of feature branch using git &#8220;rerere&#8221;"},"content":{"rendered":"<p>In this blog we were\u00a0going to discuss some &#8220;Feature branching and it&#8217;s repeated sync&#8221; disorder\u00a0and it&#8217;s cure using git &#8220;rerere&#8221; to keep the sanctity of git BPF &#8211; Branch Per Feature.<\/p>\n<p>First of all, I would like to discuss benefits of git BPF\u00a0and how we miss use it and fall in trap of <em>&#8220;Feature branching and it&#8217;s repeated sync&#8221; disorder.<\/em><\/p>\n<p><span style=\"text-decoration: underline\"><em>Some Benefits of using <strong>Git BPF :<\/strong><\/em><\/span><\/p>\n<ul>\n<li>Feature branch is used to segregate frequent merges to main branch related to particular feature or bug\/hot fix, hence you work on features independently, and so they never affect anyone else&#8217;s work during development process.<\/li>\n<li>Easy to perform code reviews and branch specific\u00a0testing on the feature branch without holding anyone if there is a bug in your code.<\/li>\n<li>Our all feature branches are forked\/created\u00a0from a master\/develop\u00a0branch (I would prefer develop branch in sync of master i.e. master is production branch, at the point of the last release).<\/li>\n<li>We need to merge regularly into a third branch forked from develop as throw-away integration branch (any forked branch from develop) to resolve merge conflicts and validate anything isn&#8217;t breaking, which can be throw-away after you use it to perform actual merges to develop.<\/li>\n<li>We can have QA branches, like idt (Integration and Developement testing), iat (Integration and acceptance testing etc&#8230;). \u00a0After performing test over there branch which contain all content from feature branches which are stable and needed in release, using merge and tested over these branches. Later being merged to master for production release<\/li>\n<li><em><strong>One of the Major purpose\u00a0of using Feature branch :<\/strong> <\/em>We branched to achieve a particular\u00a0goal (example : &#8220;adding functionality\/feature&#8221;, &#8220;hot fix&#8221;, &#8220;support&#8221;, &#8220;testing&#8221; etc&#8230;&#8221;) and for that we can have a dedicated branch to keep the history of <em>that<\/em>\u00a0branch more readable and understandable.<\/li>\n<\/ul>\n<p>There might be many more&#8230;.<\/p>\n<p><em><span style=\"text-decoration: underline\">Problem we face using <strong>Git BPF<\/strong> related to\u00a0<strong>&#8220;Feature branching and it&#8217;s repeated sync&#8221; disorder\u00a0syndrome<\/strong> :<\/span><\/em><\/p>\n<p>When 2 devs are\u00a0working on the same chunk\/part of code\u00a0over\u00a0different features branches and when they try to perform\u00a0merge, it will be obvious for them to\u00a0get the conflict over code. If feature branch is long-lived branch then they can expect a huge list of conflicts to resolve.<\/p>\n<p>To avoid that pain we mostly fall in the trap of the disorder\u00a0named <em>&#8220;Feature branching and it&#8217;s repeated sync&#8221;<\/em>. \u00a0You will start doing frequent pull of develop branch over your feature branch to remain in sync.<\/p>\n<p><strong><em><span style=\"text-decoration: underline\">Drawback of syndrome :<\/span><\/em><\/strong><\/p>\n<p>It obviate\u00a0the purpose and major goal of BPF i.e. to keep the history more readable and understandable as we kept merging master\/develop into feature branch.<\/p>\n<p>To avoid disorder, we should not commit any changes we pulled from develop branch over feature branch for the purpose of testing the stability of our feature branch. It will\u00a0led us to trap of resolving the same conflict every-time we take pull and after testing resetting branch to feature branch\u00a0state which is rather more painful and time consuming majorly in long-lived branch.<\/p>\n<p><em><span style=\"text-decoration: underline\"><strong>Cure :<\/strong><\/span><\/em>\u00a0 We need to visit and understand about cure from Git Specialist, Dr. ReReRe (<strong>Re<\/strong>use <strong>Re<\/strong>corded <strong>Re<\/strong>solution) :<\/p>\n<p>To enable &#8220;ReReRe&#8221; over git, we need to do the following :<\/p>\n<pre id=\"0499\" class=\"graf--pre\">git config --global rerere.enabled 1\r\ngit config --global rerere.autoupdate true<\/pre>\n<p><em><strong><span style=\"text-decoration: underline\">Understanding\u00a0enchanting \u00a0&#8220;ReReRe&#8221;:<\/span><\/strong><\/em><\/p>\n<p><em>For example :<\/em>\u00a0 We have a develop branch having\u00a0file named sql.properties<\/p>\n<pre>url=jdbc:mysql:\/\/localhost:3306\/\r\ndbName=rerere_dummy\r\nuserName=rerere_test\r\npassword=rerere_test\r\n<\/pre>\n<p>We created feature branch from it named &#8220;feature\/configureDatabase&#8221; :<\/p>\n<pre>url=jdbc:mysql:\/\/localhost:3306\/test\r\ndbName=rerere_test\r\nuserName=rerere_test\r\npassword=rerere_test<\/pre>\n<p>Some other person perform the same change over branch &#8220;feature\/devDatabaseConfiguration&#8221; setting :<\/p>\n<pre>url=jdbc:mysql:\/\/localhost:3306\/dev\r\ndbName=rerere_dev\r\nuserName=rerere_dev\r\npassword=rerere_dev<\/pre>\n<p>and merge it back to develop.<\/p>\n<p>Now when I am going to take pull of develop branch over\u00a0&#8220;feature\/configureDatabase&#8221; will led me to conflict. I will resolve the conflict test the changes with it. After stability and testing I need to revert them back to keep sanctity of feature branch commits dedicated to it only.<\/p>\n<p><span style=\"text-decoration: underline\">Using ReReRe is simple :\u00a0<\/span><\/p>\n<p>Create throw-away branch from develop, for example : rerereDbConfigTest<\/p>\n<p>Now checkout\u00a0rerereDbConfigTest and merge your feature branch &#8220;feature\/configureDatabase&#8221; to &#8220;rerereDbConfigTest&#8221; which will led to conflict. Resolve the conflict and run command :<\/p>\n<pre>git rerere\r\n\r\n<strong>Recorded resolution for 'sql.properties'\r\n<\/strong><\/pre>\n<p>As you can see rerere recorded the conflict resolution for file &#8220;sql.properties&#8221;.<\/p>\n<p>Now do git reset &#8211;hard over it. As your resolution is already recorded in .git\/rr-cache<\/p>\n<p><span style=\"text-decoration: underline\">Now whenever you do merge to develop branch, it will give you Conflict but with resolution :<\/span><\/p>\n<pre>Auto-merging sql.properties\r\nCONFLICT (content): Merge conflict in sql.properties\r\n<strong>Staged 'sql.properties' using previous resolution.<\/strong>\r\nAutomatic merge failed; fix conflicts and then commit the result.\r\n<\/pre>\n<p>Highlighted line above\u00a0shows, you have staged resolution of this conflict. \u00a0All you need to do is run this command to resolve conflict as per resolution recorded previously by rerere :<\/p>\n<pre>git rerere status sql.properties\r\n<\/pre>\n<p>Your file will get the resolution from the .git\/rr-cache file and conflict will get resolved from recorded cache after running above command.<\/p>\n<p>Now you just need to commit\/push your changes\u00a0over develop, no manual conflict resolution.<\/p>\n<p>It will save\u00a0your time in case of huge conflict resolution while you work on long-lived feature branches. And you can remove\u00a0or throw away &#8220;rerereDbConfigTest&#8221; after performing\u00a0testing and merging your feature branch to develop.\u00a0Make sure you don&#8217;t push throw away\u00a0branch to remote.<\/p>\n<p>What we achieve :<\/p>\n<ul>\n<li>Readable and understandable commits over feature branch, which are dedicated to it.<\/li>\n<li>Cure of &#8220;<em><span style=\"text-decoration: underline\">Feature branching and it&#8217;s repeated sync&#8221;<\/span> disorder, <\/em>keeping sanctity of Git BPF.<\/li>\n<li>Overcoming fear of merge and repeated conflict while using Git BPF over long-lived branches.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\">Some references :<\/span><\/p>\n<ol>\n<li><a title=\"Git - Branch Per Feature Documentation\" href=\"https:\/\/github.com\/affinitybridge\/git-bpf\/wiki\/Branch-per-feature-process\">Git &#8211; Branch Per Feature Documentation\u00a0<\/a><\/li>\n<li><a title=\"Git rerere command Documentation\" href=\"http:\/\/git-scm.com\/docs\/git-rerere\">Git &#8211; rerere command Documentation<\/a><\/li>\n<li><a title=\"Git rerere command usage\" href=\"https:\/\/git-scm.com\/blog\/2010\/03\/08\/rerere.html\">Git &#8211; rerere command usage<\/a>\u00a0&#8211; Detailed<\/li>\n<\/ol>\n<p>I came across this cool feature of git and thought to share with\u00a0our subscribers. Those who aren&#8217;t aware of git goodness, Hope it helps \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog we were\u00a0going to discuss some &#8220;Feature branching and it&#8217;s repeated sync&#8221; disorder\u00a0and it&#8217;s cure using git &#8220;rerere&#8221; to keep the sanctity of git BPF &#8211; Branch Per Feature. First of all, I would like to discuss benefits of git BPF\u00a0and how we miss use it and fall in trap of &#8220;Feature branching [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/24216"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=24216"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/24216\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=24216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=24216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=24216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}