After posting a few articles that talk about branching and git, a few of my clients have asked about git and branching in general. This article aims to take a high level look at branching in general. I mostly use git, so this is git based, though it’s important to note that other SCMs will have something similar.

Another important note, is that this is very high level. It does not represent a real set of changes or workflow. It’s only meant to give a general idea. Think of it more as a logical representation of git branches.

Unfortunately, git, and SCM in general is a very complex topic. If you would like a more in-depth view, using your own site or project as a reference then by all means send me an email or give me a call. If your a current client you can see your current repository from inside the tracker.

First lets go over a few very important key words. SCM is source control management, or the system used to maintain versions of your projects source (again at a very high level). HEAD is a special word, it means, basically “most current version”. HEAD can mean different things in different branches, but always means “most current version”, only the context changes. To branch is to basically derive a separate version of the source code, think of it as basically copying a file before you make changes. To merge is to blend two branches back together. Lastly a revision is simply a set of changes. Think a revision of a file or email.

I have never really found a good analogy to liken git to. Some people use a tree, but I find this to be very misleading. In git you want your branches to eventually merge back into each other. Others have used a trip on the interstate, and while this is closer, in order for this to work the interstate would need to move and not the car. So for this article I am going to forgo the analogies and use a common example.

In our sample project we have made a site that sells buttons. Everything is working great but we need to add shipping and handling to the button site. So as a client you enter the ticket to add shipping and handling. This is where we start.

Git branching example
Git branching example

Start from the bottom of the image. On the left we have what is called the master branch. This branch is where I keep the “current” working version of the site. It is almost certainly ahead of production, but matches staging, and is the next version to be pushed to production. First we add some more buttons to the site, then we fix a typo.

Now I realize that adding shipping and handling isn’t going to be as fast as fixing a typo so I create a branch called shipping. On the shipping branch I add the code for shipping and handling, then I add some support for UPS as the carrier.

Back on master I swap out an image, as you, the client requested, and publish. So at this time your production site, has no shipping and handling but has the new buttons, typos, and the changed image.

You like the changes to the site, and inquire about shipping and handling, When I give you a status update, you mention that you would also like taxes to be supported. Once again I realize this is no simple task. I create a new branch called taxes.

On taxes I add support for displaying the taxes and add in support for sales tax in certain states. Everything seems to be working so it’s time to get this back into master.

I start by merging taxes into shipping. At this point the shipping branch has shipping handling and taxes. I then merge the shipping branch into master. Now, master has, shipping, handling, taxes, image changes, typo fixes, and new buttons.

As stated this is a very simple example, a real world example could have a massive number of branches. Also notice in our example, Fed-Ex support has been added in the shipping branch but never merged into master. That means it was never pushed to production and is just being saved for later. The other really important thing to note is that I was able to work on both shipping and master branches allowing changes to go forward without having to wait for the more complicated, shipping and handling changes.

You should also note that the branches won’t contain any changes from master until they are merged. In the example, ass we were merging master, taxes, and shipping, we merged master into shipping as well. That means that when working on you Fed-Ex changes shipping will contain the change made in master.

This is a very complex topic, but I hope this has given you a general idea. Again, if you would like to use your project or site as an example, just give me a call, or send an email. Programming LLC. is about one thing. Getting your project done the way you like it. Using Agile development and management techniques, we are able to get even the most complex projects done in a short time frame and on a modest budget.

Feel free to contact me via any of the methods below. My normal hours are 10am to 10pm Eastern Standard Time. In case of emergency I am available 24/7.

Phone: (813) 421-4338
Skype: coteyr
Guru: Profile