4 C
New York
Thursday, February 2, 2023

Understanding Git-Based Version Control for Industrial Automation – Automation.com

When a robust version control system is implemented correctly, teams can focus more on the development activities instead of searching for and investigating code changes.
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 who, 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 users can answer these questions:
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 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:
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:
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:
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.

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.

Basic Git workflow steps for an Industrial Automation project include:
These steps are outlined in Figure 1.
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 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.
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.
Copia toolsets empower engineers to visualize PLC code in ladder logic, function block diagrams, and structured text languages. These toolsets can visualize code from Rockwell Automation Studio 5000 Logix Designer, Siemens TIA Portal, ABB Automation Builder, Beckhoff TwinCAT®, Lenze PLC Designer, Wago e!COCKPIT, CODESYS, and additional vendor support. Teams can follow a consistent workflow no matter what PLC vendor they choose.
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.

Git sports advanced workflows that add more control and improve collaboration. These workflows are centered around concepts known as “branching and merging.” An easy way to understand the concept of branching is to envision that every development project has a main branch where the final error-free code is stored. Every commit represents a vetted change that purposely improves the code.
Git allows users to create a parallel branch from the main branch when adding new features and creating bug fixes. This branch enables users to make changes without disturbing the main branch. If the code changes are successful, users can merge the changes back into the master branch; if they are not successful, they can be deleted.
Using the branching and merging process gives users greater control over when the main branch is changed. For example, rules can be developed and enforced so only project leads can merge code into the main branch, ensuring all changes are reviewed and approved.
Another benefit of this workflow is it keeps the project development history clean and easy to understand. Significant changes to the production code are documented in the main branch, while work in progress (WIP) is tracked and stored within development branches.
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 allows users to add more engineers to a job to meet tight deadlines (Figure 4).

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.

Obvious questions are: “What happens if two engineers change the same line of code and then merge? Which change will be accepted?” Git handles such situations with tools to resolve merge conflicts. The project lead can see both changes and choose the better one. This ability is another reason why visualizing differences between commits is so essential.
As previously stated, Copia Automation provides specific tools to visualize ladder logic. The same visualization is used when handling merge conflicts. Copia displays the rungs in questions and prompt the decision-maker to choose which change is preferred if multiple engineers change the exact area of code.
Copia understands that thorough code review, careful pull request approval, and thoughtful merge conflict resolution are essential for producing the highest quality code. Copia allows teams to add comments at the rung level to discuss and document decisions during a pull request. This context, captured throughout a project’s lifecycle, can be used to train new programmers, ensure consistency, and identify opportunities to improve.
Hopefully, at this point, there is a clear understanding of Git-based version control and the features that are meaningful to industrial automation professionals, specifically PLC programmers. When it comes to the value to a business, the primary benefit is centered around employee productivity and shortening product timelines.
With Git-based source control implemented, all individuals will spend less time searching for the files and investigating how files differ during their lifecycle. That time savings can be reinvested in high-value work—developing innovative and high-quality code.
Branching and merging enables multiple team members to work on the same automation project simultaneously. This practice has the potential to be a substantial competitive advantage for a company and ensure tight project deadlines are met.
The increased collaboration of Git-based version control also enables the business to utilize their most skilled people more efficiently. Senior control engineers can quickly review more junior engineers’ work continuously via a web app and document their feedback to help accelerate team training.
Improved code quality is another significant benefit of a Git-based version control system. Using visual diffing capabilities allows errors to be detected more readily. Formal pull request procedures ensure that only authorized people can change the production code.
A solid Git-based version control system can save businesses thousands when dealing with unexpected operational problems. If a major incident disrupts manufacturing, the last good version of the code can always be found quickly and used to restore service.
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.
Find more information and download the open-source version of Git from here or try a free version of GitHub here. If you are considering Git for your PLC programming projects, we recommend signing up for a free trial of Copia Automation.

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.
Check out our free e-newsletters to read more great articles..
©2020 Automation.com, a subsidiary of ISA


Related Articles


Please enter your comment!
Please enter your name here

Latest Articles