Understanding Git-Based Version Control for Industrial Automation

Understanding Git-Based Version Control for Industrial Automation
Understanding Git-Based Version Control for Industrial Automation

Good version control practices are essential for efficient code development. They ensure that users can track changes to files over time, understand why the changes were made and by whom, and revert to specific code versions if needed. As more engineers are assigned to a project or as more time passes between project activities, the benefits of proper version control increase. Less time is required to understand how and why a project arrived at its current state.

For an industrial automation developer, a sound version control system ensures that users can answer these questions:

  • Where is the latest version of the programmable logic controller (PLC) code, and can I access it without calling another developer?
  • Is this version of code the same as what has been deployed onto the PLC?
  • Was the latest version reviewed/approved by the proper people?
  • What has changed between this file and the previous version? Who made the change and why?
  • Can I control who can access the files at different stages of the PLC code’s lifecycle?

 
While there are many different types of version control systems, Git dominates the software industry with more than 80% market share and is used by around 100 million developers.


Git explained

Git is a mature and actively maintained open-source tool created in 2005 by Linus Torvalds (the founder of Linux). It is now the most widely used modern version control system globally. Reasons why Git became the standard include:

  • Git is distributed, meaning files and history are stored locally and in a central repository. This characteristic enables engineers to work without network access.
  • Git is fast. Since history is stored locally on the user’s device, changing versions is nearly instant.
  • Git is secure. Git uses a hashing algorithm that ensures that every edit is traceable. It is impossible to change a file or directory without Git knowing.


Today’s error-prone manual process

For an industrial automation professional who is not familiar with Git, it may be easier to understand if it is compared to the widespread and manual practice of using an “archive folder” to manage industrial automation files.


The typical archive folder workflow steps include:

1. The controls engineer creates project files on the local computer, using an installed integrated development environment (IDE), such as Rockwell Automation Studio 5000 Logix Designer or Siemens TIA Portal. The names of the files are often a user-created mix of a project name, version, and engineers initial (e.g., Mixer_DAH_V1).

2. Edits are stored by overwriting the previous file (Save) or copying and renaming the new files (Save As).

3. When work is completed to a significant state, the file or entire project folder can be zipped and copied to a central location for sharing and backup.

4. If other team members need to access the files to review or make changes, they need to download them to their local hard drive and use their development environment to view and edit the files.

It is common for controls engineers to “copy and rename” to manage a file’s history, resulting in a list of similar files distinguished by filenames and modification dates. Unfortunately, there are many problems and limitations with this workflow. For example:

  • There is no inherent information on why a file was updated or changed. Additional work is needed to document and communicate changes.
  • Project organization is based on manually naming files, which is prone to human error.
  • There is no easy way to see the difference between file versions. Some IDEs provide this capability, but only for their specific file types. 
  • Local files are not backed up regularly. Work is often lost, and the latest version of a project may not be in the archive folder.
  • Collaboration is limited. If teammates copy the same file from the central location and make changes, they cannot easily merge their work.
  • It is difficult for managers to understand the progress made on a project since the work is usually kept on local machines.
  • There is no inherent method for reviewing and approving files.
  • Setting access permissions for specific files can be challenging.
  • For large files, copying, pasting, and eventually uploading can take a significant amount of time. This fact may decrease the frequency at which projects are backed up.

 
Git alleviates these disadvantages. A basic Git-based workflow has many similarities to the archive folder workflow. Work is done locally, changes are saved and committed to the file’s history, and these committed changes are synchronized to a centralized location. There are significant benefits as Git removes the need to copy, move, and rename files manually. Git stores versions of the project and provides rich context on who, what, and why changes were made.


Basic Git workflow

Basic Git workflow steps for an Industrial Automation project include:

  1. A central repository is created on a server, which is cloud-hosted for most Git providers (GitHub, Copia, etc.).
  2. This repository is cloned to the control engineer’s local machine. It will appear on the local PC as a standard Microsoft Windows folder.
  3. The engineer creates automation files using the local IDE such as Studio 5000, saves the file in the local repository, and commits these changes to the file history when ready.
  4. When a development milestone is reached, or the engineer believes it is appropriate, the engineer pushes the committed changes to the central repository.

Meanwhile, teammates who also have cloned the central repository locally can “pull” the updated files to their local repository, so they are always working with the latest files.

Figure 1: In a Git workflow, filenames stay the same, and commit history is automatically tracked. A simple set of pull and push commands ensure that everyone has access and is working with the latest version.


A PLC file’s history can be viewed using a Git commit graph (Figure 2). Note that any previous commits can be retrieved if needed.

Figure 2: With Git, each committed change is stored with context and can be visualized as a node along a main branch of code. A simple revert command can be used to access previous changes.

While making changes, considerations include:

  • As changes are made, filenames can stay the same in Git. There is no reason for the engineer to have to use a filename to describe the project state. Git tracks the difference in each commit.
  • Tasks like creating and cloning repositories, committing, pushing, and pulling are fast and usually take only a few mouse clicks. The Git workflow is easy to execute.
  • Git never deletes or overwrites files; historical work can always be accessed if needed. (If users accidentally remove a rung and saved the file, they can revert to an earlier version. It’s like a post-save undo.)
  • A persistent Internet connection is not required. Users can work locally and then push changes later. (This is helpful when making code changes on field-based devices.)

 


Why Git hasn’t been widely adopted (yet)

As previously stated, a benefit of Git version control is tracking when files change and showing what changed. Git does this by displaying file version contents and highlighting the differences in a “diffing” process. “Diffing” is relatively fast and straightforward because most traditional software development uses text-based programming languages. In a Git “diff,” red highlight indicates lines of deleted code, and green represents new added code.

Unfortunately, PLC programming evolved differently than traditional software programming. While there are some text-based languages for PLC programming, most are done in visual languages like ladder logic and function block diagrams. This problem was compounded because many PLC vendors use different binary file formats. The inability of standard Git to display these languages reduced much of its value for many controls engineers.

For most industrial control projects, Git can indicate when and who changed files but not how those files changed. The lack of this significant benefit has slowed Git adoption.


Modern developer tools to the rescue

Copia Automation was founded to bring modern developer tools to industrial automation professionals, unlocking the productivity gains already realized in traditional software development. They have started by solving the issue around visualizing and diffing PLC code changes when using Git-based source control.
It is essential to understand that Copia renders the PLC code in its desktop app and web browser. This capability provides freedom to automation teams and accelerates code review and discussions.
Consider a junior engineer developing a section of code that controls machine safety and finishes a task late in the day. With only a web link, a manager who needs to review the code can securely log in to the Copia repository from a home computer and see the latest changes directly in a web browser (Figure 3).

Figure 3: Copia visually displays changes between commits to ladder logic files. Deleted rungs are displayed in red, and additions are shown in green.


Advanced Git workflows unlock greater value

Git supports advanced workflows that add more control and improve collaboration, known as “branching and merging.” An easy way to understand the concept is to envision that every development project has a main branch where the final, error-free code is stored. A parallel branch can then be created, enabling users to make changes without disturbing the main branch, then merge the changes into the master branch when complete.
One of the most powerful aspects of branching and merging is the ability for multiple developers to work on the same project simultaneously. Each developer can create individual branches, and when their work is complete, they can use the merge command to stitch their work together. Branch and merging allow users to add more engineers to a job to meet tight deadlines (Figure 4).


Git version control helps businesses succeed

The primary benefits of Git-based source control are centered around employee productivity and shortening product timelines. Individuals spend less time searching for files and investigating how files differ during their lifecycle. Increased collaboration enables the business to utilize their most skilled people more efficiently, as multiple team members can work on the same project simultaneously, and senior

Figure 4: Development branches can exist simultaneously, allowing multiple engineers to work together on the same code. Merging can combine all work together into the main branch.


control engineers can quickly review more junior engineers’ work and document feedback continuously via a web app. The time savings can be reinvested in high-value work developing innovative and high- quality code.
Additionally, a solid Git-based version control system can save a business significant budget when dealing with unexpected operational problems. If a major incident disrupts manufacturing, the last working version of the code can always be found quickly and used to restore service.


Next steps

Git is the ubiquitous source control solution for software development, and its use has accelerated the speed at which code is developed and deployed. It is proven to shorten development timelines, increase quality, and maximize operational uptime.

While saving and storing code is slightly different from the traditional archive folder workflow, Git-based source control for industrial automation projects is easy to learn and worth the benefits.

All images courtesy of Copia Automation.

This feature originally appeared in the ebook Automation 2022: IIoT and Industry 4.0 (Volume 3).

About The Author


Darren Henry is vice president of marketing at Copia Automation. With more than 20 years of experience in marketing best-in-class software products, he has a deep knowledge of manufacturing and DevOps solutions.
Familiar with both startups and established companies, he has held marketing leadership roles at Atlassian, OpsGenie, Onshape, InVue, and DS SolidWorks. He has also served as an advisor to several manufacturing startups. An expert in 3-D CAD, Henry has a degree in mechanical engineering from the University of Florida.


Did you enjoy this great article?

Check out our free e-newsletters to read more great articles..

Subscribe