The Artima Developer Community
Sponsored Link

Java Buzz Forum
Git: Automatic Merges With Server Side Hooks (For The Win!)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Mathias Bogaert

Posts: 618
Nickname: pathos
Registered: Aug, 2003

Mathias Bogaert is a senior software architect at Intrasoft mainly doing projects for the EC.
Git: Automatic Merges With Server Side Hooks (For The Win!) Posted: May 2, 2013 5:25 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Mathias Bogaert.
Original Post: Git: Automatic Merges With Server Side Hooks (For The Win!)
Feed Title: Scuttlebutt
Feed URL: http://feeds.feedburner.com/AtlassianDeveloperBlog
Feed Description: tech gossip by mathias
Latest Java Buzz Posts
Latest Java Buzz Posts by Mathias Bogaert
Latest Posts From Scuttlebutt

Advertisement
This will be standard and easily understandable to anyone who has already been working with git for a while. If you come from a centralized, old school version control background and you are thinking of switching to Git – which I heartily recommend – you will find the topic of this post awesome, almost magical. Not as magical as mini ponies but … you get the picture. It is still awesome to me even though I’ve been working with git for a while already. I am talking about automated merges from stable/maintenance branches to master. Real World Scenario Let me give you an example taken from the way the Stash development team works. The Stash team maintains, at any given point in time, several stable code lines that are out in the market (let’s limit the example to 2.1, 2.2 and 2.3 releases) while at the same time they merge feature branches into master in preparation for an upcoming release branch 2.4. Now check out the magical bit. Whenever a maintenance fix is applied to any of the stable branches it is automatically merged(!!) in cascade to the master branch. No user interaction is required (except in the rare occasion when a conflict arises). (It is understood that a fix is committed to a stable branch only after the change has been peer reviewed, all tests pass, the builds are green and the performance metrics have not been affected). As you can see a fix applied to the 2.2 code line will automatically be first applied to the 2.3 branch and then from the 2.3 branch to master. All without user interaction. How cool is that? How is that even possible you ask? Can I have that too please? Well of course. Automatic Merges are the rule, not the exception One of the areas where git excels at is merging code lines. git is so good at this that most of the times the merges just work. Except when they don’t. In the case of stable code lines, merge conflicts are even more rare given that the amount of code involved in those fixes is generally small. How to setup Automated merges, the manual way with hooks Let me show you how you can implement a similar workflow. First let’s write something that will accomplish it on a local machine. The first part of the puzzle is to write a script that you can run after you’ve committed a fix on a stable branch: 1234567891011121314151617181920212223242526#!/bin/sh # Automatically merge the last commit through the following branches: # 2.1 -} 2.2 -} 2.3 -} master CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) LAST_COMMIT=$(git rev-list -1 HEAD) echo Automatically merging commit $LAST_COMMIT from $CURRENT_BRANCH rippling to master case $CURRENT_BRANCH in 2.1)   git checkout 2.2 && git merge $CURRENT_BRANCH   git checkout 2.3 && git merge 2.2   git checkout master && git merge 2.3   git checkout $CURRENT_BRANCH   ;; 2.2)   git checkout 2.3 && git merge 2.2   git checkout master && git [...]

Read: Git: Automatic Merges With Server Side Hooks (For The Win!)

Topic: A surplus of innovation Previous Topic   Next Topic Topic: Bad Actors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use