Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Status
colourGreen
titleLAST TESTED ON CHECKMK 2.02.0P1


Panel
borderColorblack
bgColor#f8f8f8
titleTable of Contents

Table of Contents

Step-by-step guide

  1. Go to Setup → General → Global Settings → Edit global setting

  2. Place an X to enable GIT version control
    Screenshot displaying the location of enable GIT version control within global settingsImage Modified
    .
  3. Click Save
    .
  4. Activate changes

Git ignore

By default, Checkmk creates the following .gitignore files:

...

  • ~/etc/check_mk/conf.d/wato/.gitignore

    Code Block
    languagebash
    themeRDark
    title~/etc/check_mk/conf.d/wato/.gitignore
    OMD[mysite]:~/etc/check_mk/conf.d/wato$ cat .gitignore
    
    !*


Push to a remote repository


  1. Add repository

    Code Block
    languagebash
    themeRDark
    OMD[mysite]:~/etc/check_mk$ git remote add origin https://github.com/mygituser/test.git

    .

  2. Setup the upstream branch

    Code Block
    languagebash
    themeRDark
    OMD[mysite]:~/etc/check_mk$ git push --set-upstream origin mastermybranchname

    .

  3. Verify the git configuration

    Code Block
    languagebash
    themeRDark
    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 "mastermybranchname"]
    remote = origin
    merge = refs/heads/mastermybranchname

    .

  4. Push local configuration to masterto mybranchname

    Code Block
    languagebash
    themeRDark
    OMD[mysite]:~/etc/check_mk$ git push --set-upstream origin masterUsernamemybranchnameUsername 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] mastermybranchname -> mastermybranchname
    Branch 'mastermybranchname' set up to track remote branch 'mastermybranchname' from 'origin'.

    .

    Tip

    Manage your personal access tokens


    Screenshot of GIT repository for testingImage Modified


Automate Git push

If you would like to automate Git push, you can do this with a Git post commit hook

  1. Create the post-commit file

    Code Block
    languagebash
    themeRDark
    OMD[mysite]:~$ vi ~/etc/check_mk/.git/hooks/post-commit

    .

  2. Add the following

    Code Block
    languagebash
    themeRDark
    title~/etc/check_mk/.git/hooks/post-commit
    #!/bin/sh
    git push -u origin mybranchname

    .

  3. Save the file
    .
  4. Make the file executable

    Code Block
    languagebash
    themeRDark
    OMD[mysite]:~$ chmod +x ~/etc/check_mk/.git/hooks/post-commit


Useful commands

Panel
borderColorblack
bgColor#F8F8F8
  • Show changes before commit

    Code Block
    languagebash
    themeRDark
    git diff

    .

  • View system status

    Code Block
    languagebash
    themeRDark
    git status

    .

  • Automatically record changed files

    Code Block
    languagebash
    themeRDark
    git add . -A

    .

  • Transfer all files to the repository

    Code Block
    languagebash
    themeRDark
    git commit -am "There is a comment here"

    .

  • This command shows what has happened so far

    Code Block
    languagebash
    themeRDark
    git log

    .

  • Write all recent changes to a file


    Code Block
    languagebash
    themeRDark
    git format-path -1

    .

  • Which files were changed?

    Code Block
    languagebash
    themeRDark
    git diff --stat

    .

  • Apply patch files from other participants: First only in test mode, then really:

    Code Block
    languagebash
    themeRDark
    git apply --check patchdate
    
    git apply patchdate

    .

  • Create a directory and fetch repository (e.g., via https):

    Code Block
    languagebash
    themeRDark
    mkdir gitlocal ; cd gitlocal
    
    git clone 'https://user@server.de/repository'

    .

  • Create a local branch

    Code Block
    languagebash
    themeRDark
    git branch mybranch

    .

  • Switch to a local branch

    Code Block
    languagebash
    themeRDark
    git checkout mybranch

    .

  • Show Branches

    Code Block
    languagebash
    themeRDark
    git branch

    .

  • Back to master to mybranchname and pick up changes

    Code Block
    languagebash
    themeRDark
    git checkout mastermybranchname
    
    git pull

    .

  • Apply changes to the master the mybranchname branch

    Code Block
    languagebash
    themeRDark
    git checkout mybranch
    
    git rebase master

    .

  • Transfer changes to the remote repository

    Code Block
    languagebash
    themeRDark
    git push origin mybranch:master

    .

  • Customize your shell prompt always to show the branch you are working on. Add Git additional information

    Code Block
    languagebash
    themeRDark
    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:

    Code Block
    languagebash
    themeRDark
    . /etc/bash_completion.d/git
Info
Original article published at http://www.karl-deutsch.at
  • /
versionsverwaltung_mit_
  • git
.html and written by Karl Deutsch.


Filter by label (Content by label)
showLabelsfalse
max5
spacesKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ( "git" , "kb-how-to-article" , "git" ) and type = "page" and space = "CONKB"
labelskb-how-to-article

Page Properties
hiddentrue


Related issues


...