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 [...]