PLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

 

 How to create a Blog Entry

Version Control - The Lazy Way

Life of a programmer is hard enough as is. Why not make your life easier and outsource the version control of your projects to some dedicated services? Most programmers in the IT world are familiar with Git, but for some of the OT programmers in this community, this is a brand new concept. When working with different colleagues at the same project sharing code becomes even more of a hassle, a service like GitHub makes it easy to share and work together on the same code. This Blog guides you trough your first steps in using Git and GitHub to keep your code and projects in order. 


 In this blog I'll be using GitHub and the GitHub client for windows, but please note there are more options including GitLab. I just like the ease of use of the GitHub Client!


Setting up a repository on GitHub

 

Step 1 - Download and install the GitHub Client for Windows

Actually, the first step would be to create a GitHub account, but that's somewhat out of the scope of this blog.

  1. The Client can be downloaded from here.
  2. Follow the Installation Guide
  3. Log In to your GitHub Account

 Step 2 - Create a folder or repository for your project

A repository is a place for your project to live. Make one folder for each project! Everytime something changes in this folder the GitHub client will detect it and you'll be able to save or push your changes to the online repository on GitHub.

  1. Click on "Create a New Repository on your hard drive ... "
  2. Give your new repository a name and description.
  3. You can change the path for the repository if you wish, or leave it be (the lazy way)
  4. Click Initialize this repository with a README (Lazy doesn't mean, following best practice and document your code!)
  5. Create the repository

the lazy way new repo

 Step 3 - Create A PLCnext Project

Git works great with text based files. Luckily in PLCnext Engineer there is an option to save your project as a whole lot of text files, perfect for Git and thus for our GitHub client!

  1. Open PLCnext Engineer and start creating a project as your used to.
  2. When ready to save your project, choose Save Project As ( F12)
  3. Browse to your GitHub repository (default: This PC/documents/GitHub )
  4. Save your project as an "Uncompressed Project" 

save uncompressed

 Step 4 - Commit your changes

To "save" changes to your repository you need to commit them to a branch. What exactly a branch is, I'll explain later, for now you just have to remember that you need to commit your changes to a branch in order to save them.

Give your commit a new and a short description so you can remember what changed exactly!

first commit

Step 5 - Publish or Push your repository

The final step to create a repository online is to push our local repository to GitHub. This as easy as pushing a button or pressing (ctrl + p ). Choose if your code should be private and if it belongs to you, or an organisation.

publishing

Step 6 - Document!

press ( Ctrl + shift + G) to view the repository online on GitHub in your browser. Voila! There is you PLCnext Project on GitHub. Remember the "Initialize README"? That's the text you're seeing now in front of you. In the README.md you should explain the structure of the project, the purpose and maybe some contact information for future reference.

For now make some changes, to the README.md file by clicking on the pencil. The file is "Written" in MarkDown more information about MarkDown can be found here

If you've made some changes, again commit to the master branch!

Step 7 - Pull changes to your local repository

The Windows Client will detect that some changes where made to the Repository on GitHub. Don't forget to pull the changes to start working on the latest version again!


Tips & Tricks

Issue Tracker

GitHub has a wonderful issue tracker, use it to track known issues in your software and discuss solutions with the other stakeholders

 Projects

Use the build-in Project Bord to keep track of your task with an kanban bord. If you feel like it you can automate your kanban with built in triggers to make life even easier.

 Branches

Aah, here we are. See, I said I was going to explain what branches are! Well, I'll let GitHub explain what branches are ...

Use a branch to isolate development work without affecting other branches in the repository. Each repository has one default branch, and can have multiple other branches. You can merge a branch into another branch using a pull request.

Going to make a lot of changes or implement a new feature? Create a branch to keep your changes isolated and merge your "feature branch" into your master branch with a pull request. 

 Release

Ready to deploy a project? Create a release to add to your AS Build!