This article details how to enable Git version control for WATO within Checkmk.
LAST TESTED ON CHECKMK 2.0.0P1
Step-by-step guide
- Go to Setup → General → Global Settings → Edit global setting
- Place an X to enable GIT version control
. - Click Save
. - Activate changes
Git ignore
By default, Checkmk creates the following .gitignore files:
~/etc/check_mk/.gitignore
~/etc/check_mk/.gitignoreOMD[mysite]:~/etc/check_mk$ cat .gitignore # This file is under control of Checkmk. Please don't modify it. # Your changes will be overwritten. * !*.d !.gitignore *swp *.mk.new
~/etc/check_mk/conf.d/.gitignore
~/etc/check_mk/conf.d/.gitignoreOMD[mysite]:~/etc/check_mk/conf.d$ cat .gitignore * !wato
~/etc/check_mk/conf.d/wato/.gitignore
~/etc/check_mk/conf.d/wato/.gitignoreOMD[mysite]:~/etc/check_mk/conf.d/wato$ cat .gitignore !*
Push to a remote repository
Add repository
OMD[mysite]:~/etc/check_mk$ git remote add origin https://github.com/mygituser/test.git
.
Setup the upstream branch
OMD[mysite]:~/etc/check_mk$ git push --set-upstream origin master
.
Verify the git configuration
OMD[mysite]:~/etc/check_mk$ cat ~/etc/check_mk/.git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [user] email = check_mk name = check_mk [remote "origin"] url = https://github.com/mygituser/test.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
.
Push local configuration to master
OMD[mysite]:~/etc/check_mk$ git push --set-upstream origin masterUsername for 'https://github.com': mygituser Password for 'https://mygituser@github.com': Enumerating objects: 65, done. Counting objects: 100% (65/65), done. Delta compression using up to 8 threads Compressing objects: 100% (55/55), done. Writing objects: 100% (65/65), 30.69 KiB | 10.23 MiB/s, done. Total 65 (delta 6), reused 39 (delta 1), pack-reused 0 remote: Resolving deltas: 100% (6/6), done. To https://github.com/mygituser/test.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'.
.
Manage your personal access tokens
Useful commands
Show changes before commit
git diff
.
View system status
git status
.
Automatically record changed files
git add . -A
.
Transfer all files to the repository
git commit -am "There is a comment here"
.
This command shows what has happened so far
git log
.
- Write all recent changes to a file
git format-path -1
.
Which files were changed?
git diff --stat
.
Apply patch files from other participants: First only in test mode, then really:
git apply --check patchdate git apply patchdate
.
Create a directory and fetch repository (e.g., via https):
mkdir gitlocal ; cd gitlocal git clone 'https://user@server.de/repository'
.
Create a local branch
git branch mybranch
.
Switch to a local branch
git checkout mybranch
.
Show Branches
git branch
.
Back to master and pick up changes
git checkout master git pull
.
Apply changes to the master branch
git checkout mybranch git rebase master
.
Transfer changes to the remote repository
git push origin mybranch:master
.
Customize your shell prompt always to show the branch you are working on. Add Git additional information
GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWUPSTREAM="legacy verbose git" export PS1='\u@\h:\w$(__git_ps1 " (%s)")\$ '
.
If you get an error message saying that git_ps1 cannot be executed, add the following line to the .bashrc:
. /etc/bash_completion.d/git
Related articles