Using git for Industrial Automation – Part 2 – Branches

In an earlier article I explained the basics of git and how to use GitKraken, one of the various graphical interfaces of git.  Now we are going to take this a couple steps further and show you how to use branches in git with RTU/PLC programming.

Branches are an important function of any version control system. They allow the programmer to develop multiple versions of an application independently of each other while retaining the ability to merge two versions together. It might be that you need a branch for each major revision of an application, or a branch for the production version of your code and a branch for the development version. Some people use branches for developing particular features, others combine all variations of the above.

I’m going to go back to my example I had from before. We had started a project that had a Telepace programming file and a Red Lion Crimson HMI file. We are going to assume these two apps were implemented in the field. Now the client is asking for a minor revision to the Telepace file. They would like to add some extra pump control.

So to get this done we are going to create a branch so we do not affect our ‘master’ branch, which should be the version in active use. Lets open up GitKraken and open the repository for the demo project we created. I hadn’t started anything else since last time so it opened up straight away.

Then we are going to find the newest commit, right-click and select Create Branch. Enter a name. I chose “PumpAddition”. GitKraken will also ‘checkout’ the branch as soon as it is created. Essentially git/GitKraken is storing the master as a snapshot and has created a new version of your project in the PumpAddition branch.

Now I want you to open up some project files and make a few changes. I added some basic start/stop logic on a new network in Telepace. Then ‘stage’ the changes in GitKraken and make a new commit. You will see that your pump addition branch now has a commit ‘ahead’ of the master. This is all good. GitKraken is just showing that after that point in time for this project we made commits on a branch outside of master. Now we have two branches. The master branch which has the application as implemented in the field and a new PumpAddition branch with our new development. We can develop the PumpAddition branch without having to worry about losing the code in the field.

So after working on that project for a while I have two or three commits in the PumpAddition branch. Now we are going to implement this new logic in the field. As well as downloading my new tested programs to the field equipment I will now ‘merge’ the two branches.

Right-click on the PumpAddition branch and select merge. Now your PumpAddition branch will show as merged up with the master branch.

This is what my project looks like after I finished my merge.

At this point we have merged our changes into the master branch which is what is live in the field. But we are still working on the PumpAddition branch, which is generally not what we want now that the . So we want to ‘checkout’ the master branch. Right-click the master branch and select Checkout master.

Now we are live on the master branch. We can continue making changes and commits. The PumpAddition branch stays there in GitKraken marking that point in time. You can go back to that point in time by checking out the PumpAddition branch which brings your project folder back to the state of the project at that period of time. WARNING: Make sure you close all your development apps first! Some industrial apps do not like have their files tampered with while they are open.

You can use branching to test or try odd-ball code too. Make as many branches as you like. I have not done this too much yet in my projects but I can see where this would make it easy to see when a programming project or major change happened to a particular site. The branches would mark what changes happened and the commits might mark all the minor milestones in those projects.

The next post on git for industrial programming will cover remotes and using remotes as a backup or central spot for your projects and programming files.

 

Leave a Reply