home icon contact icon rss icon

Managing many app variants with git

One of my friends works on application that have basically two variants with slight modifications between each of them. It can be horror to work with two similar applications without good SCM.

Happily we have git :)

How to deal with this problem? It’s based on git approach from one of my previous posts so read it first.

Main task is to find last commit with which applications were identical. Let’s say that it’s:


commit b576de0csadcscs846ef933edf75e449d12db39d
Author: FooBar
Date:   Thu Apr 16 13:07:01 2009 -0700

    Last touches before creating appliaction variant.
We must create a branch that will be ancestor for both variants:

git checkout -b both b576de0c

Now branch both keeps only things that are identical in every variant of application. If you want to make some changes and merge them with both applications just:


git checkout both
git checkout -b bugfix23
# fix this nasty bug
git checkout both
git merge bugfix23 # merge it back to both
git checkout variant1 
git merge both # merge the changes to variant 1
git checkout variant2
git merge both # merge the changes to variant 2

Why can’t I just do it without both?


# don't do it!
git checkout variant1
git checkout -b bugfix23 # now we are on bugfix23 which has variant's 1 commits in history
# fix this nasty bug
git checkout variant1 
git merge bugfix23 # everything is fine, mergeing changes from bugfix
git checkout variant2
git merge bugfix23 # now your repo is a mess - you've just merged all of the variant's 1 commits
So what to do if you accidentally commited changes to branch inheriting from one of the variants? You can just cherry-pick one of the commits:

git cherry-pick cs6dc876

It’s like a merge, but merging only one commit.

Leave a Comment