First steps with CODESYS Git

First steps with CODESYS Git

This is in no way a complete overview on what CODESYS Git offers. It is merely meant as a primer to get you up and running with git on forge quickly.

Git is a popular open source distributed version control system. Understanding and mastering the basics is easy. However, the best results are achieved via 'learning by doing'. This blog-post tries to condense the bare essentials for CODESYS Git so you can get started quickly.

Be aware that Git is a totally different beast from svn! If you have previous experience with svn you will have a (small) head start in understanding the basic key concepts of Git.

CODESYS Git usage requires a valid Professional Developer Edition or a Demo License (free). If
the entire community (you all) will ask politely, CODESYS will surely try to enable free usage for use with CODESYS Forge

General Git terminology

  • Git: 'global information tracker' or more commonly 'git', is a 'container name' for a source code repository
  • Main: Since 2020 'master' is being replaced with 'main', in this guide we will use 'main'
  • Remote main: The remote 'main' repository, which is usually hosted somewhere online or somewhere in your network and it contains the entire project code and it's entire history. Also referred to as 'origin'
  • Local main: Usually a local clone from a remote main. The local clone is an exact copy of the remote main repository and acts a local starting point for your contributions
  • Branch: A working branch or snapshot of 'Local Main' which acts as a point for you to add contributions in. Once you have tested the contributions (and stage/commit them), you can merge them back into your local main
  • Merge: the act of 'merging' changes from branch A into branch B. You should use this to update a local main with a development branch or to update working branches
  • Checkout: the act of selecting an active working branch, the IDE will switch to this version so you can work in it
  • Stage: the act of preparing files and code changes on the current checkout.
  • Commit: Adds staged files and changes into the current checkout branch. A username, emailadres and a commit message are to provided onneach commit. The more descriptive your commit message is, the better as this will help you search for mutations if you need to without digging into the history too much. Changes are always commited to the current checked out branch
  • Push: commits from local branches are ultimatly merged into the local main.
    When you are satisfied with the result, e.g some feature or ticket is completed, the local main needs to be synchronised with the remote main. In order to di this we must 'push' all changes into the remote main.
  • Pull or 'Pull request': A pull request can be sent to the admin of a remote main. This will notify the admin that a new code is ready to be merged into the remote main. After checking this new code the admin can decide if he merges it (partially or entirely).
  • Sync: The remote main and your local main should ideally stay synchronised (have the same content) and should be synced on a regular basis. This is achieved by 'pulling' the remote main into local main and pull these changes into a working branch. In general, a synced main and working branch will ensure that merging changes back into main will not cause conflicts.
  • Flow: There are many ways or practices (flows) to use git, however there is no single best flow as this depends on many factors. In general a good flow mainly depends on group needs, group size and group growth. A good git flow will not cognitively drain you but helps you focus on development.

'Pull Requests' and 'Squash' will be on the roadmap for an updated version

Installing CODESYS Git

  • Start the CODESYS Installer (Start > CODESYS > CODESYS Installer),
  • Select the installation you wish to extend with git and press "Change",
  • In AddOns select the browse category,
  • Now enter Git in the search bar and start the search by pressing enter,

  • Select it and press install and follow the instructions,

  • Wait for the installation to complete,
  • Ready!

Typical git flow

Initial setup is done a few times in the development cycle, but usually significantly less then the repeated flow, unless you like to tinker around much or you have a need for many git's

Add cForge Git repository

  • Add a new "Git" repository on a project where you are Admin via "Add New..." menu,

  • Once the Git repository has been added to cForge, you can use it to check in and out code as your "remote main"

Initial setup

  • Initialise remote main git see [[## Add cForge Git repository]]
  • Load project into CODESYS
  • Initialise (create) local main git

  • Stage/commit loaded project into local main

  • Add remote main as a location in local main

  • Push local main to the remote main

Keywords: create remote, load project, create local, commit local, add remote, push remote

Repeated flow

  • Branch and checkout the local main into a new named branch for your first contribution

  • After completion, stage and commit the changes onto your current working branch

  • Checkout the local main

  • Merge the previous working branch into the local main

  • Push local main into remote main
  • Ready!

Keywords: branch/checkout, code, stage/commit, merge, push

History overview

  • This Tab shows an in depth historical overview of you current checkout
    • working branch named "Dev_PrimaryHost" has been created from the local main
    • In this branch, "FB_Payload_Old" has been deleted, staged and committed into "Dev_PrimaryHost"
    • After this the branch has been merged with "Local Main"

CODESYS svn to git migration

  • Checkout from SVN
  • Disconnect from SVN
  • Git > Initialize Local repository
  • Git > Remote > Add the remote git location you made in the previous step
  • Git > stage/commit and push to the remote origin

Pull request vs Push

..

Squash

..

Posted by hermsen 2021-07-11

Log in to post a comment.