Product Features
Tech Tips

.gitignore: What it does and how to use it

Published on
February 1, 2023

If you’ve been leveraging the benefits of Git-based Source Control for your team’s PLC development, you may be familiar with the .gitignore file, one of Git’s many useful tools. 

Copia automatically generates a .gitignore for every new repository, with useful default settings to improve your experience tracking changes to PLC code.

With that said, it can still be helpful to know how .gitignore works, and how you can use it yourself.

Copia repository showing the automatically generated .gitignore file

If your repository has a .gitignore file in it, Git will use it to deliberately ignore some files from tracking.  This can be useful for ignoring automatically generated files and background files that applications like MS Word and your PLC development environment create, such as .Sem and .Wrk files created by Rockwell Automation Studio 5000, and included in Copia’s default .gitignore.  This reduces clutter, and keeps the size of a repository down, reducing the amount of space your PLC projects take up on your Controls Engineers’ workstations.

Some of the default .gitignore settings packaged with every new Copia repository to minimize project clutter

The .gitignore file is a plain text file that Git tracks alongside your PLC code, meaning any changes to it that you push to the remote repository are automatically propagated to your entire team the next time they pull to their local repositories.  

Copia .gitignore file with some custom patterns manually added

Being a plain text file, your repository’s .gitignore can be modified in any text editor, like MS Notepad.  Removing a line will allow git to track previously untracked files and folders, and adding a line adds a new rule to ignore files and folders previously tracked with Git.  Crucially, the rules in .gitignore allow you to not only ignore specific files, by adding the (case-sensitive) filename and extension to it, but also to ignore files based on patterns in the name.  An asterisk allows you to match file types to ignore, like “*.jpg” (without quotes) to ignore all files with the .jpg extension, as well as files containing a known pattern in the name, like “Log_*” to ignore files beginning with “Log_” or “*tmp*” to ignore files with “tmp” anywhere in the name.  For more granular control, take a look at the official git documentation on .gitignore here, which describes additional formatting (such as case-insensitive patterns) you can use to fit your specific use case.