Git branches to manage third party app customization
Take control of your customizations with this simple process


Preface:

I have been using this technique to customize different types of third party projects for years. I originally wrote about it back in 2009 in this popular post regarding the management of customizations on top of the ever changing Drupal code base. That post is very long winded and overly technical for most people, this post will serve as an abridged version covering only the branching concept.

The Problem:

A third party has developed some code you would like to leverage, however, you require customizations to their code for your implementation. The third party is actively developing their code base, so you need to be able to easily update their underlying code while keep your customizations intact.

The Solution:

We will use Git to track both their changes and our changes. We will have two branches; master will track their changes and custom will track our changes. We will never make any changes to the master branch other than to pull in updates from the third party. All of our modifications will be made in our custom branch. When the third party makes a change we will pull it into our master branch and then propagate it into our custom branch. All deployments and builds will be done from the custom branch.

An Example:

Get the third party code (this will create the master branch):

$ git clone https://github.com/third_party/project.git

Create the custom branch for our modifications:

$ git checkout -b custom
  # ... do your customizations ...
$ git add .  
$ git commit -a -m "Initial customizations"

At this point you can create your first build/deployment from the custom branch…

When the third party updates their code and you want to incorporate their changes:

$ git checkout master  
$ git pull origin master  
$ git checkout custom  
$ git pull . master

Now you have merged their changes into the custom branch and you are ready to build/deploy the custom branch again…

Update:
Since I originally wrote this, I have changed my process slightly when incorporating third party updates. Here is how I do it now…

$ git checkout master  
$ git pull origin master  
$ git checkout custom  
$ git rebase master

Update 2: I am not sure if I perfer pull or rebase. There are pros and cons with both, so you should research for yourself and figure out which is best for your purposes.