Config GIT for VSCode editor

I recently started to use HA. I bought the green box to run it.
Before really diving in, I want to setup GIT so that my configuration gets version control.
I run my own git server for my local projects.
I am unable to get GIT on HA to authenticate.

  1. created a new repository in ssh://home.local/git/HAConfig.git
  2. initialised GIT in my /homeassistant/config/ folder
  3. added the address in (1) as the remote origin
  4. copied my keys to /homeassistant/config/certs/
  5. configured GIT with my user.name

Attempting to do a git push from the action (…) menu I find that permissions are denied.
Attempting to push from the Terminal shows that is is asking for the password for [email protected] - instead of my username.

I assume root is the current user on the green box??
Any suggestions for a work around please?

1 Like

What tool are you using?

How did you do that, precisely?

I am using the Studio Code add-on.
I performed the push from the … menu of GIT commands

Trying to remember … either there was an init menu command, or I did this from the Terminal shelf in the Studio Code editor.

I got nowhere with this approach.
My guess was I would never be able to fix the fact GIT in HA would insist on using root as user :-/

I got this working partially by following these instructions.

  • Having to use GitHub instead of my own server is deeply ironic for Home Assistant IMHO.
  • The GIT integrations in the FileEditor GUIs do not work, this is only working from the Terminal AFAICS.

Not really sure how vscode works as an HA addon, but git uses the keypair stored in ~/.ssh to authenticate.

Not sure how putting the certificate in /config/certs is supposed to achieve anything, unless you tell it to use it, but I might miss a piece.

See, e.g., ssh - How to tell git which private key to use? - Super User

EDIT: BTW, you could use the certificate generated with ssh-keygen on your own server, if you add the generated public key to your ~/.ssh/authorized_keys

Now, that’s git / ssh 101, not much to do with HA itself tbh

One of the steps in the guide that I pointed out above, is to configure GIT with the non-standard location for keys.
Searching for solutions, I saw people using config/certs and config/.ssh … neither of which would have worked without extra configuration I believe.

You can use any location under /config.
That’s one of the few directories that are common across all addons.
Addons are independent docker containers, if you were not aware.

Note also that that git configuration is independent of github: it works the same way for any git “server” if you do what I told about authorized_keys, above.

I use GIT for all my HA config. I do it a bit differently. I do all my config in YAML and don’t use the HA editors. FWIW this is what I do. :blush:

  1. On my laptop I have a directory call ha_config, that is attached to a private GitHub repo
  2. I use vscode to edit the files in there
  3. When I’ve completed a change, I then use git to review the changes and make sure everything looks right (aka a code review), if it does then
  4. I have a shell command ha-compare that does a diff between ha_config and the running HA system. This allows verification of what is actually different.
  5. I then run ha-deploy which transfers the files to the ha system
  6. I then run ha-check which issues a REST API command to ask HA to validate the config
  7. I then run ha-restart which issues a REST API command to restart HA
    8, If the changes work then I com it to git,

Periodically via another command I’ll copy the running ha back to the laptop and check in changes to .storage

That’s the simplified version. I have two HA systems for difffent houses. Since I want stuff consistent. I create my own object / class definitions (automations, template, UI) in a separate git repo and run scripts that build the config into those ha specific repos. That’s just an extra layer.

1 Like