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.
1 Like

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.

1 Like

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.

4 Likes

Not sure if you ever got this solved, but there is a way to do this. I thought I’d drop this response anyway, in case anyone is looking for an answer and finds this page…

There a now a /config/ssh directory in which you can place all your ssh config files and pub/priv keys.

That folder is sym link mapped to the /root/ssh folder…

In there you can add your SSH config and public/private key pair files…and it will get picked up by ssh, and in turn git, when you use an ssh style remote.

The ā€˜git’ link to my ha config repository on my home git server is: `ssh://[email protected]:10022/gil/ha.cancas.com.git``

so in my ssh config file (in /config/ssh/config) I have:

Host nas2.home
    HostName nas2.home
    User git
    Port 10022
    IdentityFile ~/.ssh/gilha

With my private key stored in /config/ssh/gilha and the matching public key registered on my home git server.

You can test it out by trying to just ssh to the remote address (e.g. for me that would be ssh nas2.home) to make sure that it works and that the remote host has been added to know_hosts file… and then try using git push/pull etc…

Hope that helps!

G./