How to organize my openHAB setup with multiple git repos?

Hi guys,

I’m currently in the process of switching openHABian for an docker-compose based setup. Since I have two openHAB server I would like to have one git repo with shared configs and seperate repos for configs which are unique.
Example: My docker-compose.yml belongs to the shared repo since I use the same services on both servers. But an *.items file would belong to server A’s repo since I have different items on these two servers.

  • Git submodules might be an option if I had all unique configs in an subfolder of the shared repo but that is not the case. Also, as far as I understand them they are not really for a use case where I have one subrepo (subrepo server A) in one installation and a different subrepo in the second installation (subrepo server B)
  • Interleaved git repos seem only possible if I put the unique repo in an gitignored subfolder

Intended Setup (broad for shared files, normal for files unique for each server):

  • main folder
    • .gitignore
    • docker-compose.yml
    • openhab_userdata/etc/org.ops4j.pax.logging.cfg
    • some docker related scripts
    • serviceX.env-files
    • .env
    • openhab_conf
      • icons/*
      • transform/*
      • .gitignore
      • items/*
      • rules/*
      • sitemaps/*
      • and all the other openhab-config files…

The idea would be to clone my shared repo and my server specific repo to a machine and to be good to go…
Has someone an idea how to achieve such merged repos where the merging is not defined by the folder structure?

BR,
Felix

After a bit of googling and phrasing my idea in different ways this stackoverflow post gave me the right input how to use branching and only one repo instead of trying to violate git :sweat_smile:

More detailed:

  1. Create an new repo (new folder, git init)
  2. Commit all files and folder marked above as ‘shared’ (git add . & git commit -m “create common”)
  3. Rename branch master to common ( git branch -m master common)
  4. Create and checkout branch serverone ( git checkout -b serverone)
  5. Commit all files & folders unique to server one
  6. Checkout branch common (git checkout common)
  7. Create and checkout branch servertwo
  8. Commit all files & folders unique to server two

A few tipps:

  • you can use git log --oneline --decorate --graph --all to get an ‘graphical’ overview in your shell about your branches and commits
  • if you do changes to your common files use git checkout serverone (or …two) and git merge common to merge the changed common files back into your server branches

Source: Pro Git, Chapter Branching

1 Like