Git Version Control

The Git Version Control dialog in the Quick Menu (CTRL+Q) commits the project configuration to a Git repository, pulls a committed version back into the database, restores earlier commits and switches branches.

Updated 6 min read
On this page (9 sections)
  1. Overview
  2. Settings
  3. Creating a Personal Access Token on GitHub
  4. Repository Status and Output
  5. Commit & Push
  6. Pull & Import to DB
  7. Recent Commits and Restore
  8. Branches
  9. Several servers on one repository

The Git Version Control dialog keeps the project configuration in a Git repository. Every commit holds the complete configuration as JSON files (parameters, pages, alarms, events, schedules, devices, variables, users, UDT definitions and instances, recipes, reports) together with the project files, so a commit is a full snapshot of the project that can be compared, restored and shared between servers.

Open the Quick Menu with CTRL+Q and click Git in the Project group.

The dialog is available to members of the Administrators user group. Every action, including reading the status, requires those rights. On a redundant pair only the primary node accepts commits, pulls and restores.

The server keeps a local copy of the repository next to the application. The dialog works on that local copy and synchronises it with the remote repository on every Commit & Push and Pull & Import.

Settings

Expand Settings at the bottom of the dialog to connect the server to a repository. Click Save Settings when the fields are filled in. The server then clones the repository right away, or re-points the existing local copy at the new address, and the panels above refresh with the result. A problem with the address or the token is reported in the Output panel together with the saved message.

FieldDescriptionExample
Remote URLHTTPS address of the repository. Credentials inside the address are removed; the token below is used instead.https://github.com/company/plant-a.git
GitHub UsernameUser name of the account that owns the token. Optional for GitHub: when empty, the token is used as the user name.engineer01
Personal Access TokenToken with read and write access to the repository. Required to clone, fetch and push. See Creating a Personal Access Token on GitHub below.github_pat_...

The token is stored encrypted and is never shown again. The placeholder of the Personal Access Token field tells whether a usable token is stored: leave the field empty to keep the current token, or type a new one to replace it.

Settings expanded at the bottom of the Git Version Control dialog. The Personal Access Token placeholder shows that a token is stored.
The token is encrypted with a key that belongs to the server it was entered on. After a project transfer, a database restore or a switch to the other node of a redundant pair, the stored token cannot be used there. The Repository Status panel then shows a warning, the token field asks for the token again, and Settings opens by itself. Enter the token once more on that server; the Remote URL and the user name carry over unchanged.

Creating a Personal Access Token on GitHub

Use a fine-grained personal access token that is limited to the project repository. On GitHub, click the profile picture, then Settings, Developer settings, Personal access tokens and Fine-grained tokens, and click Generate new token.

SettingValue
Resource ownerThe account or organization that owns the repository. A token for an organization repository can require approval by an organization owner before it works.
Repository accessOnly select repositories, with the project repository selected.
ContentsRead and write. Required: the server clones, fetches, commits and pushes through this permission.
MetadataRead-only. Added by GitHub automatically and required.
Repository access limited to the project repository, with Contents set to Read and write.
The Git Version Control dialog only uses Git operations on the repository. Other permissions, such as Pull requests, are not used by the dialog and can be left out.

Copy the token as soon as GitHub shows it; it is shown only once. Paste it into the Personal Access Token field of the Git Version Control dialog and click Save Settings.

A token has an expiry date, shown on its page on GitHub. After that date the server can no longer fetch or push. Click Regenerate token on GitHub, or create a new token, and enter it in the Personal Access Token field again. The Remote URL and the GitHub Username stay as they are.

Token page on GitHub with the expiry date and the Regenerate token button.

Repository Status and Output

Repository Status shows the branch the local copy is on, the folder of the local copy and whether the exported files differ from the last commit. Click the refresh button next to the heading to read it again. When no local copy exists yet and the settings are complete, the first refresh clones the repository.

Output shows the result of the last action: the commit that was created, the push result, the steps of an import, or the reason an action was refused.

Clear Local deletes the local copy of the repository. Nothing is deleted on the remote. The next action clones the repository again from the Remote URL. Use it when the local copy is in a state the dialog cannot recover from.

Commit & Push

Type a message in the commit message field and click Commit & Push. The server exports the complete configuration and the project files into the local copy, commits them as the logged-in user and pushes the branch to the remote. When nothing changed since the last commit, the Output panel reports that there is nothing to commit.

A push is refused when the remote holds commits this server does not have yet, for example commits made from another server. Run Pull & Import to DB first to bring them in, then commit and push again. Nothing is ever force-pushed.

Pull & Import to DB

Pull & Import to DB fetches the current branch from the remote and imports the committed configuration into the database. The Import Options dialog asks how the import is applied.

OptionDescription
ReplaceWipes the current configuration and imports the committed version exactly. Records that exist only in the current database are removed.
Merge (show diff)Shows the differences between the current database and the committed version before anything is written. Records that exist only in the current database are kept.
  • The merge preview groups the differences per configuration table, with a tab per table and the counts of added, local only and modified records.
  • Every added or modified record has a Keep Local / Incoming switch. Added records offer Skip instead of Keep Local. Open a modified record to compare the fields side by side.
  • Click Confirm Merge to write the incoming records that are still selected. Local only records are never deleted by a merge.
  • Both options end with a reload of the application. The session is closed by the import, so the browser returns to the login page afterwards.
The connection settings of the server itself (Remote URL, GitHub Username, Personal Access Token and the repository folder) are kept during an import, in Replace mode as well as in Merge mode, when they are set on this server. A commit made on another server therefore never replaces the credentials that this server uses to reach the repository. The same applies to the redundancy shared secret.

Recent Commits and Restore

Recent Commits lists the latest commits of the current branch with their hash, date, author and message. Click the refresh button next to the heading to fetch the list again.

Restore on a commit opens the same Import Options dialog as Pull & Import to DB, applied to that commit instead of the latest one. Replace loads the commit exactly; Merge shows the differences with the current database first. Restoring does not move the branch: the newer commits stay in the list and can be restored again later.

Branches

The Branches list holds the local branches and the branches of the remote that have no local copy yet. Select a branch and click Switch to check it out; a remote branch is created locally on the first switch. The current branch is marked in the list.

Type a name in the new branch name field and click Create & Switch to start a branch from the current commit. The branch reaches the remote with the next Commit & Push. Pull & Import to DB fetches the current branch from the remote, so it reports that the branch is not found until that first push has been done; the local copy is left as it is in that case.

Several servers on one repository

A repository can be shared by several servers, for example an engineering server and a production server, or the two nodes of a redundant pair. Each server keeps its own local copy and its own token. The dialog serialises its actions on the server, so a refresh that runs while an import is in progress waits for the import to finish instead of interfering with it.

New Project and Import Project clear the local copy of the repository, so the first Commit & Push after them starts from a fresh clone and commits the new project on top of the repository history.

Something missing or wrong in this article? Contact us