manuveli/git-ha-ppens
关于
Git Integration for Home Assistant to allow versioning your configuration
其他项目实测星标增长
- 24小时
- +2
- 7天
- +3
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
git-ha-ppens
GitOps for Home Assistant — right from your UI.
GitOps for Home Assistant. Edit your config in VS Code or directly on GitHub, push the changes, and your HA instance pulls them automatically. Roll back any breaking change directly from the Home Assistant UI. Review config changes in a pull request before they ever reach your live system.
git-ha-ppens brings native git directly into Home Assistant — auto-commit on file change, auto-push to your remote, and now auto-pull when new commits arrive. All configured through the UI, no command line needed.
📥 Installation
Prerequisites
Requirements:
- 🏠 Home Assistant 2024.1 or later
- 🔧 Git available to the Home Assistant Core runtime
The Home Assistant Core image used by Home Assistant OS and the official Home Assistant Container image already include Git, so no separate installation is normally required. git-ha-ppens checks for Git during setup. Custom container images must include Git in the Home Assistant Core image itself.
HACS (Recommended)
- Make sure HACS is installed
- Click the badge above — or go to HACS → Integrations → ⋮ → Custom repositories and add:
with category Integrationhttps://github.com/manuveli/git-ha-ppens - Search for git-ha-ppens and click Install
- Restart Home Assistant
- Go to Settings → Devices & Services → Add Integration and search for git-ha-ppens
Manual Installation
- Download the latest release from the Releases page
- Copy the
custom_components/git_ha_ppensfolder into yourconfig/custom_components/directory - Restart Home Assistant
- Go to Settings → Devices & Services → Add Integration and search for git-ha-ppens
📑 Table of Contents
- 📥 Installation
- ✨ Features
- 🔁 GitOps Workflow
- ⚙️ Configuration
- ⏪ Roll back to a historical configuration
- 🤖 AI Commit-Messages
- 🚀 Services
- 📊 Sensors & Entities
- ⚡ Events
- 💡 Example Automations
- 🛡️ Auto-Generated .gitignore
- 🔧 Troubleshooting
- 🤝 Contributing
- 📄 License
✨ Features
🤖 Automatic Version Control
- 👁️ File watcher detects config changes in real time (powered by watchdog)
- ⏱️ Configurable debounce interval (default 5 min) to batch changes and avoid excessive commits
- 📝 Auto-generated commit messages listing the changed files
🔁 Auto-Sync (GitOps)
- 🔄 Periodic git fetch checks the remote on a configurable interval (default 5 min, range 60–3600s)
- ⬇️ Auto-pull when the integration detects your instance is behind the remote
- ⬆️ Auto-push sends any clean local commits upstream, including commits created by ESPHome, VS Code, or manual Git commands
- ✅ Pre-deploy check (optional) — validates incoming remote changes after pulls or push-fallback merges and automatically rolls them back if the check fails
🔧 Manual Control
- 8 services callable from automations, scripts, or Developer Tools:
git_ha_ppens.commit— create a commit with an optional custom messagegit_ha_ppens.push— push commits to the configured remotegit_ha_ppens.pull— pull from remote (auto-backs up uncommitted changes first)git_ha_ppens.fetch— fetch from remote without merging (updates ahead/behind counts)git_ha_ppens.sync— commit + push in one stepgit_ha_ppens.diff— get the current diff of uncommitted changesgit_ha_ppens.discard_changes— discard tracked local changesgit_ha_ppens.gc— safely clean up leftover Git data and optimize the repository
- Push, Pull, and Fetch buttons when a remote is configured, plus an optional disabled-by-default Discard Local Changes button
- Native rollback from the configuration UI — select a historical commit, preview the changes, validate the configuration and restore it
🛡️ Security & Secrets
- 🚫 Automatic
.gitignoreforsecrets.yaml,.storage/, databases, logs, and more - 📦 Core/Container backup protection excludes HA-created
.tararchives without hiding other files in a user-createdbackupsdirectory - 🔍 Best-effort secret warning checks staged or modified configuration files when the integration loads
- 🔔 Fires a
git_ha_ppens_secret_detectedevent when potential secrets are found - ⚠️ Secret warnings do not block commits or pushes and are not a substitute for a carefully maintained
.gitignore - ✍️ Optional SSH commit signing so GitHub or GitLab show commits as verified (off by default)
☁️ Remote Support
- Push and pull from GitHub, GitLab, Bitbucket, or any git remote
- HTTPS with personal access token or SSH key authentication
📊 Visibility & Monitoring
- 12 sensors + 1 binary sensor for real-time git status and repository size
- Events for commit, push, pull, fetch, garbage collection, errors, and secret detection
- 🧹 Repository maintenance: a repair warns about large leftover Git data, with optional scheduled
git gc - Build dashboards, notifications, and automations around your config history
🩺 Diagnostics
- Full diagnostics support via Settings → Devices & Services → git-ha-ppens → Diagnostics
- Sensitive values are automatically redacted
🔁 GitOps Workflow
GitOps means your git repository is the single source of truth for your Home Assistant configuration. Instead of editing files directly on your HA instance, you manage changes through git — and your instance automatically stays in sync.
With git-ha-ppens you get a full GitOps loop without any extra tooling:
Edit config in VS Code / GitHub → push to remote
↓
git-ha-ppens fetches periodically (default: every 5 min)
↓
Detects your instance is behind → auto-pull
↓
(optional) Pre-deploy check → rollback if config is invalid
↓
Home Assistant is up to date ✓
Why this matters
- Edit from anywhere — use your local editor, the GitHub web UI, or any other git client. Changes reach HA automatically.
- Review before it goes live — open a pull request for config changes and merge only when you're ready.
- Instant rollback — select a previous configuration directly in the Home Assistant UI. The integration restores it as a new commit without rewriting history or requiring Git commands.
- Safe deploys — enable the optional pre-deploy check to run a Home Assistant configuration check on incoming changes. If it fails, the remote merge is rolled back automatically and your instance keeps running on the last working config.
- Full history — every config change is a commit. Know exactly what changed, when, and why.
Enabling the GitOps loop
- Configure a remote repository (GitHub, GitLab, etc.) in the integration setup
- Enable Auto-Pull in the commit settings
- Set a Fetch Interval (default 5 min) so the integration checks for remote changes periodically
- Optionally enable Auto-Push to send clean local commits upstream automatically, including commits created by external tools
- Optionally enable the Pre-deploy check to validate incoming changes and roll back automatically if the config is broken
That's it. From this point on, your HA config and your git remote stay in sync automatically.
🛡️ Pre-deploy check: When enabled, every incoming remote merge — whether triggered by a pull or by a rejected push that needs to integrate remote commits — runs a Home Assistant configuration check after merging and before the result is pushed. If the check reports errors, git-ha-ppens performs a
git reset --hardback to the last working commit, fires agit_ha_ppens_check_failedevent, and creates a persistent notification listing the errors — so a bad commit on the remote can't take down your instance. This check validates the live configuration directory, so it only runs whenrepo_pathis your HA config directory (e.g./config).The rejected remote revision is not retried until the remote advances. Once you push a corrective commit, Auto-Pull explicitly merges and validates the corrected history. If Auto-Push is also enabled, git-ha-ppens publishes that validated merge automatically so the repository returns to a fully synchronized state. A real content conflict is aborted cleanly and still requires manual resolution; remote history is never force-pushed.
⚙️ Configuration
The integration is configured entirely through the UI. The setup flow has 3 steps:
Step 1: 📁 Repository Settings
| Option | Description | Default |
|---|---|---|
repo_path |
Path to the HA configuration directory | /config |
git_user |
Git author name for commits | (required) |
git_email |
Git author email for commits | (required) |
Step 2: 🔄 Auto-Commit Settings
| Option | Description | Default |
|---|---|---|
auto_commit |
Automatically commit when files change | true |
auto_push |
Push any clean local committed history to the remote, including commits created by external tools | true |
auto_pull |
Pull automatically when the instance is behind the remote | false |
pre_deploy_check |
Validate incoming remote merges and roll back if the check fails | false |
commit_interval |
Debounce interval in seconds (30–86400) | 300 |
scan_interval |
Status polling interval in seconds (10–3600) | 30 |
fetch_interval |
How often to fetch from remote in seconds (60–3600) | 300 |
Step 3: ☁️ Remote Repository (recommended; required for GitOps sync)
A remote repository is optional only if you want to use git-ha-ppens for local
version history, status monitoring, and configuration restores. Configure a
remote to use Push, Pull, Fetch, off-device backups, or the automatic GitOps
workflow. The auto_push, auto_pull, and fetch_interval settings only take
effect when a remote is configured.
| Option | Description | Default |
|---|---|---|
remote_url |
Git remote URL (HTTPS or SSH; plain HTTP for local network hosts) | (empty) |
auth_method |
none / token / ssh |
none |
auth_token |
Personal access token (for HTTPS or local HTTP) | (empty) |
auth_username |
Username paired with the token | oauth2 |
ssh_key_path |
Path to SSH private key file | (empty) |
The oauth2 authentication username preserves existing GitHub and GitLab
setups. Bitbucket repository, project, or workspace access tokens commonly use
x-token-auth; Bitbucket API tokens can use x-bitbucket-api-token-auth or the
account's Bitbucket username. The setting is ignored for SSH and unauthenticated
remotes.
Self-hosted Git servers (Gitea, Forgejo, GitLab, …)
Self-hosted servers work like any other remote; host names and IP addresses are both supported. Copy the clone URL your server shows for the repository:
| Setup | Example remote_url |
|---|---|
| HTTPS with token | https://git.example.com/user/homeassistant.git |
| SSH (default port) | [email protected]:user/homeassistant.git |
| SSH (custom port) | ssh://[email protected]:2222/user/homeassistant.git |
| Plain HTTP in the local network | http://192.168.1.10:3000/user/homeassistant.git |
Plain, unencrypted http:// remotes are accepted only for hosts inside your
local network: private, loopback, link-local, and CGNAT/Tailscale
(100.64.0.0/10) IP addresses, localhost, single-label names such as a
Docker service name (http://gitea:3000/…), and names ending in .local,
.lan, .home.arpa, or .internal. Other hosts must use HTTPS or SSH, so a
token is never sent over the internet in plain text. Keep in mind that even in
the local network, HTTP transmits the token and your configuration
unencrypted; HTTPS (for example with a Let's Encrypt certificate obtained via
the DNS-01 challenge, which needs no public exposure) or SSH is preferable.
HTTPS remotes need a certificate that Git trusts. Self-signed certificates are not supported; use SSH or HTTP in the local network for such servers instead.
🧹 Repository maintenance (General Settings only)
Interrupted Git operations (for example a Home Assistant restart while a large
file is being staged) can leave temporary files in .git that Git never
removes on its own. git-ha-ppens measures the Git directory every ten minutes
and raises a repair when more than 1 GiB of such leftover data has accumulated.
| Option | Description | Default |
|---|---|---|
auto_gc |
Periodically run a standard git gc |
false |
auto_gc_interval_days |
Days between automatic garbage collection runs (1–30) | 7 |
Garbage collection always uses Git's standard, non-aggressive git gc. Only
leftovers and unreachable objects older than two weeks (Git's default
gc.pruneExpire) are removed, because newer files may still belong to a Git
operation that is running at the same time, for example from an editor add-on.
History is never rewritten. Scheduled runs skip a cycle while another
git-ha-ppens operation is active and never delay the status updates. The first
run on a large repository can take several minutes and use noticeable CPU.
✍️ Commit signing (optional, Options menu only)
git-ha-ppens can sign every commit it creates with an SSH key, so that GitHub or GitLab show it as Verified and branch rules that require signed commits are met. Signing is off by default: existing and new installations behave exactly as before until you enable it.
Requirements: Git 2.34 or newer and ssh-keygen on the Home Assistant host.
- Create a dedicated signing key without a passphrase.
.ssh/is excluded by the default.gitignore:ssh-keygen -t ed25519 -N "" -C "git-ha-ppens signing" -f /config/.ssh/git_signing - Add the content of
/config/.ssh/git_signing.pubto your Git host as a signing key (on GitHub: Settings → SSH and GPG keys → New SSH key → Key type: Signing Key). An authentication key alone is not enough. - Make sure the Git email in the git-ha-ppens settings is a verified email address of that account; otherwise the host shows the signature as unverified.
- Open Settings → Devices & Services → git-ha-ppens → Configure → Commit
signing, enable signing and enter the absolute path of the private key.
git-ha-ppens checks the Git version,
ssh-keygen, that a key inside the repository is ignored and not tracked, and signs a test message before it saves the setting.
Every commit git-ha-ppens creates is signed: automatic and manual commits, backup commits before a pull, merge commits from pulls and pushes, and restore commits. Commits pulled from the remote keep their original signatures.
If a commit cannot be signed (for example because the key was moved),
git-ha-ppens does not fall back to an unsigned commit. Your changes stay in
the working tree, the git_ha_ppens_error event fires as usual and a repair
explains the problem. It disappears after the next successfully signed commit.
To stop signing, disable it in the same menu.
💡 Tip: All settings can be changed later via Settings → Devices & Services → git-ha-ppens → Configure. The options menu provides General Settings, Edit .gitignore, Restore configuration, and Commit signing.
⏪ Roll back to a historical configuration
You can safely restore an earlier configuration without leaving Home Assistant or using Git commands:
- Open Settings → Devices & Services → git-ha-ppens → Configure → Restore configuration.
- Choose one of the 20 most recent earlier commits. For an older state, select Enter an older commit SHA and enter its ID.
- Review the selected commit, the newer commits that will be undone, the affected tracked files, and the diff statistics.
- Confirm the restore and, when a remote is configured, choose whether to push the new restore commit immediately.
The current HEAD is shown above the recent-commit selector as active and
cannot be selected. To undo only the latest commit, select the first earlier
commit directly below it. The selected commit represents the exact tracked
configuration snapshot that will be restored.
The working tree must be completely clean, including staged, unstaged, and untracked files. This prevents an unrelated local edit from being lost or included in the restore. Ignored files and other files not tracked by Git are not part of the snapshot and remain untouched.
After explicit confirmation, the integration restores the tracked tree from
the selected commit and runs a Home Assistant configuration check when the
repository is the live HA configuration directory. A failed check or Git
operation restores the original HEAD, index, and working tree. On success, a
new commit such as revert: restore configuration to abc1234 is created and
verified to exactly match the selected historical snapshot.
This is an additive, history-preserving rollback. It does not reset or rewrite branch history, and it never force-pushes. The default for pushing the new restore commit follows the Auto-Push setting. If the push fails, the valid restore commit remains local and can be sent later with the Push button.
🤖 AI Commit-Messages
By default, git-ha-ppens generates simple commit messages listing the changed files — for example Auto: config.yaml changed or Auto: 3 files changed. This works great out of the box and does not require any AI setup.
If you want more descriptive, context-aware commit messages, you can optionally enable AI-generated commit messages. The integration uses Home Assistant's built-in Conversation service to analyze the git diff and generate a meaningful commit message — powered by whichever AI agent you have configured in HA (OpenAI, Google Generative AI, Ollama, etc.).
✅ Enabling AI Commit-Messages
AI commit messages can be enabled during the initial setup (Step 2: Auto-Commit Settings) or at any time later via Settings → Devices & Services → git-ha-ppens → Configure.
| Option | Description | Default |
|---|---|---|
ai_commit_messages |
Enable AI-generated commit messages | false |
ai_agent_id |
Conversation agent to use | (empty) |
💡 Tip: Leave
ai_agent_idempty to use Home Assistant's default conversation agent. If you have multiple AI agents configured, you can specify exactly which one should generate your commit messages.
🔎 Diff Selection & Privacy
Before calling the conversation agent, git-ha-ppens builds a compact, bounded
view of the changes and distributes the available context across changed files.
The full output returned by git_ha_ppens.diff is not affected.
Common passwords, API keys, access and refresh tokens, authorization headers,
credential-bearing URLs, and private keys are redacted on a best-effort basis
before the prompt is sent. Redaction is an additional safeguard, not a
guarantee. Continue to exclude sensitive files such as secrets.yaml and
.storage/ with .gitignore, especially when using a cloud-hosted conversation
agent.
🛡️ Fallback Behavior
AI commit messages are designed to never interfere with normal operation:
- 🔒 If AI is disabled (default), the integration works exactly as before — no AI code is executed at all
- ⚠️ If AI is enabled but the conversation agent is unavailable or returns an error, the integration silently falls back to the standard auto-generated message
- ✅ Commits are never blocked by AI failures — your configuration changes are always saved regardless of AI availability
📌 No AI? No problem. The integration is fully functional without any AI agent configured. The AI feature is a purely optional enhancement.
🚀 Services
The git-ha-ppens device page provides an optional Discard Local Changes button. When a remote repository is configured, it also provides Push, Pull, and Fetch buttons under Controls. The Push button first commits all pending changes using the configured standard or AI commit-message behavior, then immediately pushes them to the remote. Pull and Fetch run the same operations as the corresponding services below.
The destructive Discard Local Changes button is disabled by default and
must be enabled from its entity settings. It restores staged and unstaged
changes to tracked files back to HEAD. Untracked files are preserved. This is
not a historical rollback, does not reset to the remote branch, and cannot undo
a change after auto-commit has already created a commit.
| Service | Description | Parameters |
|---|---|---|
git_ha_ppens.commit |
Stage all changes and create a commit | message (optional) — custom commit message |
git_ha_ppens.push |
Push commits to the configured remote | — |
git_ha_ppens.pull |
Pull from remote (backs up uncommitted changes first) | — |
git_ha_ppens.fetch |
Fetch from remote without merging — updates the ahead/behind counts | — |
git_ha_ppens.discard_changes |
Permanently discard staged and unstaged changes to tracked files; untracked files are preserved | — |
git_ha_ppens.sync |
Commit + push in one step | message (optional) — custom commit message |
git_ha_ppens.diff |
Get the current diff of uncommitted changes | — (returns response data) |
git_ha_ppens.gc |
Run a standard git gc: remove leftover Git data older than two weeks and optimize the repository without rewriting history |
— |
Example: Call sync from an automation
action:
- service: git_ha_ppens.sync
data:
message: "Manual sync from automation"
Example: Get the current diff
The diff service returns response data containing the diff content and a status summary. Use it in scripts or automations to inspect changes before committing.
action:
- service: git_ha_ppens.diff
response_variable: git_diff
📊 Sensors & Entities
Sensors
| Entity | Description | Attributes |
|---|---|---|
sensor.git_ha_ppens_last_commit |
Last commit hash (short) | message, author, full_hash |
sensor.git_ha_ppens_last_commit_time |
Timestamp of last commit | — |
sensor.git_ha_ppens_uncommitted_changes |
Number of changed files | changed_files, untracked_files, staged_files |
sensor.git_ha_ppens_branch |
Current branch name | — |
sensor.git_ha_ppens_remote_status |
Sync status (e.g. "in sync", "ahead 3") | ahead, behind, remote_configured, has_upstream, total_commits |
sensor.git_ha_ppens_commits_ahead |
Number of local commits not yet pushed | — |
sensor.git_ha_ppens_commits_behind |
Number of remote commits not yet pulled | — |
sensor.git_ha_ppens_last_fetch_time |
Timestamp of last successful fetch | — |
sensor.git_ha_ppens_last_pull_time |
Timestamp of last successful pull | — |
sensor.git_ha_ppens_last_push_time |
Timestamp of last successful push | — |
sensor.git_ha_ppens_repo_size |
Total size of the .git directory (diagnostic, refreshed every 10 minutes) |
pack_size, pack_count, loose_size, loose_object_count |
sensor.git_ha_ppens_garbage_size |
Size of leftover temporary Git files (diagnostic, refreshed every 10 minutes) | garbage_file_count, last_gc_time, auto_gc |
Binary Sensors
| Entity | Description | Device Class |
|---|---|---|
binary_sensor.git_ha_ppens_dirty |
on when there are uncommitted changes |
problem |
⚡ Events
Use these events as automation triggers to build notifications, dashboards, or recovery workflows.
| Event | Fired when | Data |
|---|---|---|
git_ha_ppens_commit |
A commit is created | hash, message, author, changed_files, auto |
git_ha_ppens_push |
Commits are pushed | commits_pushed |
git_ha_ppens_pull |
Commits are pulled | commits_pulled, changed_files, auto |
git_ha_ppens_fetch |
A fetch completes | — |
git_ha_ppens_check_failed |
A pull or historical restore was blocked and rolled back by the configuration check | errors, auto |
git_ha_ppens_restore |
A historical snapshot was restored as a new commit | target_hash, target_message, restore_hash, commits_restored, changed_files, pushed, auto |
git_ha_ppens_gc |
A garbage collection finished | git_dir_size_before, git_dir_size_after, garbage_size_before, garbage_size_after, freed_bytes (all in bytes), auto |
git_ha_ppens_error |
A git operation fails | operation, error |
git_ha_ppens_secret_detected |
Potential secrets are found in staged or modified files during the load-time scan | findings, count |
💡 Example Automations
🔔 Notify when your instance is behind the remote
A useful GitOps signal: let HA notify you when new commits are available on the remote but haven't been pulled yet (e.g. if auto-pull is disabled).
automation:
- alias: "Git: Notify when behind remote"
trigger:
- platform: numeric_state
entity_id: sensor.git_ha_ppens_commits_behind
above: 0
action:
- service: notify.mobile_app
data:
title: "git-ha-ppens"
message: "{{ states('sensor.git_ha_ppens_commits_behind') }} new commit(s) available on the remote."
⬆️ Auto-push after every commit
automation:
- alias: "Git: Push after commit"
trigger:
- platform: state
entity_id: sensor.git_ha_ppens_last_commit
action:
- service: git_ha_ppens.push
🔔 Notify when changes are uncommitted for over an hour
automation:
- alias: "Git: Remind to commit"
trigger:
- platform: state
entity_id: binary_sensor.git_ha_ppens_dirty
to: "on"
for: "01:00:00"
action:
- service: notify.mobile_app
data:
title: "git-ha-ppens"
message: "You have uncommitted configuration changes."
📅 Weekly configuration snapshot
automation:
- alias: "Git: Weekly snapshot"
trigger:
- platform: time
at: "02:00:00"
condition:
- condition: time
weekday:
- sun
action:
- service: git_ha_ppens.commit
data:
message: "Weekly config snapshot"
🚨 Alert on secret detection
automation:
- alias: "Git: Secret detected alert"
trigger:
- platform: event
event_type: git_ha_ppens_secret_detected
action:
- service: notify.mobile_app
data:
title: "⚠️ git-ha-ppens Security Alert"
message: "Found {{ trigger.event.data.count }} potential secret(s) in staged or modified files!"
🛡️ Alert when remote changes are blocked by the pre-deploy check
automation:
- alias: "Git: Pre-deploy check blocked remote changes"
trigger:
- platform: event
event_type: git_ha_ppens_check_failed
action:
- service: notify.mobile_app
data:
title: "🛡️ git-ha-ppens: Remote changes blocked"
message: >-
Config check failed, rolled back to the last working state:
{{ trigger.event.data.errors | join(', ') }}
🛡️ Auto-Generated .gitignore
The integration automatically creates a .gitignore with sensible defaults for Home Assistant on first setup.
You can customize the .gitignore entries at any time via Settings → Devices & Services → git-ha-ppens → Configure → Edit .gitignore. The built-in editor lets you add, remove, or modify entries directly from the UI.
Only tracked files that are not ignored become part of commits, remote backups,
or historical restores. Home Assistant's UI-managed .storage directory is
excluded by default because it can contain credentials and internal state in
addition to dashboard configuration.
| Category | Entries |
|---|---|
| Sensitive files | secrets.yaml, .storage/, .cloud/, tls/, .ssh/, .jwt_secret, SERVICE_ACCOUNT.json |
| HA Core/Container backups | backups/*.tar, tmp_backups/*.tar (only for the live HA config repository on installations without Supervisor) |
| Databases & logs | *.db, *.db-shm, *.db-wal, *.log, home-assistant_v2.db, home-assistant.log*, zigbee.db, OZW_Log.txt |
| System files | .HA_VERSION, known_devices.yaml, ip_bans.yaml |
| Python cache | __pycache__/, *.pyc, *.pyo |
| Runtime & other | .git/, deps/, tts/, .venv/, .cache/, .claude/, custom_components/, www/snapshots/, .ha_run.lock, .exports, .timeline, .vacuum |
| Zigbee2MQTT | zigbee2mqtt/state.json, zigbee2mqtt/coordinator_backup.json |
| Editor swap files | *.swp, *.swo |
📌 Defaults are applied once during initial setup. After that, you can freely edit
.gitignore— your changes will be preserved across restarts.
Home Assistant Core and Container installations store locally created backup
archives below the configuration directory. These compressed .tar files can
contain the complete configuration and, depending on the backup, the database;
they are large, binary, and potentially highly sensitive. When the configured
repository is the live Home Assistant configuration directory and no Supervisor
is present, git-ha-ppens therefore adds the precise root-relative patterns
backups/*.tar and tmp_backups/*.tar. Home Assistant OS/Supervised uses its
separate Supervisor backup storage, and repositories outside the live config
directory are not changed. Files such as backups/notes.yaml, nested files, and
similarly named directories elsewhere remain trackable.
Existing installations receive the same protection through a versioned
one-time migration. A git-ha-ppens-managed .gitignore is extended only when
Git confirms that its existing rules do not already cover the archives. Matching
archives that were already tracked are removed only from the Git index; the
files on disk and unrelated staged, unstaged, or untracked changes are preserved.
For a manually managed .gitignore, git-ha-ppens never adds rules: it logs a
warning that names any missing pattern and points to Configure → Edit
.gitignore.
⚠️ Removing an archive from the index affects future commits only. It does not remove data from existing local or remote Git history. If a backup archive was already pushed, inspect the repository history and assume credentials in the archive may have been exposed. Rotate affected credentials and clean the history using an appropriate manual process if necessary. git-ha-ppens never rewrites history or force-pushes this migration.
🔧 Troubleshooting
Start with Settings → Devices & Services → git-ha-ppens → Diagnostics and the Home Assistant logs. Diagnostics redact configured credentials and make it easier to identify repository, permission, and remote-status problems.
❌ "Git is not installed"
The Home Assistant Core image used by Home Assistant OS and the official Home Assistant Container image already include Git. If setup still reports this error, restart Home Assistant and install any pending Core update. For a custom container image, install Git in that image during its build.
If your prompt starts with [core-ssh ~], you are inside the separate
Terminal & SSH add-on. Git is bundled with the official add-on, but on an
Alpine-based terminal image it can also be installed with:
apk add git
This makes Git available for manual commands inside that terminal container,
for example against the shared /config directory. It does not install Git
for git-ha-ppens: the integration runs inside Home Assistant Core and therefore
needs Git in the Core container.
If the error occurs with an up-to-date official Home Assistant image, include your Home Assistant version and diagnostics when reporting the problem.
❌ Nothing is pushed / remote status is "no remote" or "not pushed"
- Confirm that a remote URL is configured under Configure → General Settings
- Enable Auto-Push if clean local commits should be sent automatically. This also includes commits created by ESPHome, VS Code, or manual Git commands; no additional git-ha-ppens commit is required
- Press the Push button to commit pending changes and push them manually
- Check the Home Assistant logs if the remote was configured but could not be verified
- A completely empty remote is the simplest first-time setup. If the remote already has history, compatible histories are merged automatically; conflicts fail safely and are never resolved by force-pushing over remote commits
- When the remote rejects a push (for example GitHub email privacy, a protected branch, an oversized file, or a diverged history that cannot be merged automatically), git-ha-ppens raises a repair under Settings → System → Repairs with the remote response and the steps to resolve it. It disappears automatically after the next successful push
❌ Push fails with "permission denied", "401", or "403"
- When the remote rejects the credentials, git-ha-ppens raises a repair under Settings → System → Repairs. For token authentication you can enter and verify a new token directly in that repair; it disappears automatically after the next successful synchronization
- Check that the remote URL is correct and the repository exists
- Ensure the token or access key can read and write repository contents
- For GitHub classic tokens, this normally means the
reposcope; fine-grained tokens must have access to the target repository and Contents read/write permission - Verify the token authentication username for your provider:
oauth2for existing GitHub/GitLab setups, commonlyx-token-authfor Bitbucket repository access tokens, or the value required by your provider - For SSH, ensure the private-key path is accessible from Home Assistant Core and the public key is registered with the provider
❌ Auto-pull is not happening
- Auto-Pull is disabled by default and requires a configured remote
- Press Fetch and check the
commits_behindandlast_fetch_timesensors - Confirm that the incoming commits are on the tracked branch
- If the pre-deploy check blocked the pull, review the persistent notification, fix the remote configuration, and push a new commit. The same failing revision is skipped; the new revision is merged and validated automatically. With Auto-Push enabled, the recovered merge is also pushed back to the remote
- If Git reports a real merge conflict, git-ha-ppens aborts the merge without changing either branch. Resolve the conflicting changes manually, then use Pull or Push again
❌ ESPHome or another app created an embedded Git repository
ESPHome Device Builder
runs separately, but it can write to the shared /config directory. Its
version history adopts an existing parent Git repository. If ESPHome starts
before /config/.git exists, however, it can create /config/esphome/.git.
Git may then record esphome as a Gitlink instead of backing up the YAML files
themselves.
git-ha-ppens detects nested .git directories, .git files, and indexed
Gitlinks before changing repository contents or history. It blocks setup and
runtime mutations with a Home Assistant repair. This setup error is an
intentional safety stop, not a crash: open Settings → System → Repairs.
The repair offers a reversible Migrate the ESPHome repository action only
when it can prove that exactly /config/esphome/.git is a simple Device
Builder-managed repository. It refuses repositories with remotes, submodules,
extra worktrees, active Git operations or locks, ignored esphome/ paths,
missing ignore rules for known secrets and Device Builder runtime state,
unexpected index entries, or ambiguous ownership. Before confirming the
migration, make sure ESPHome cannot write version-history data:
- Open the ESPHome Device Builder Web UI. On Home Assistant OS or Supervised, go to Settings → Apps → ESPHome Device Builder and select Open Web UI.
- Open the menu in the top-right corner and select Settings.
- Under Appearance, enable Expert Mode, then turn off Save version history.
If that setting is unavailable, or if you prefer not to change it, stop the ESPHome add-on or Device Builder instead. The repair then:
- moves the inner
.gitdirectory atomically into a private.git/git-ha-ppens-recovery/...directory instead of deleting it; - prepares the real ESPHome files in a separate temporary Git index;
- rejects Gitlinks, secrets,
.esphome/, key files, and pairing files; - publishes the prepared index only if the real outer index is unchanged.
The success screen shows the recovery path. Keep that directory until you
have verified the ESPHome YAML files in the remote repository. With Auto-Commit
enabled, the staged snapshot is committed normally; otherwise use Commit
or Sync. The inner commit history is retained in the recovery copy but is
not merged into the outer history. Restart ESPHome if you stopped it. You may
also turn Save version history back on if you want ESPHome to create a
commit whenever a configuration is saved. It should then use /config as its
Git work tree instead of creating /config/esphome/.git. Confirm this with:
git -C /config/esphome rev-parse --show-toplevel
The expected output is /config. The ESPHome log may alternatively report
Version history active (git work tree: /config).
If automatic migration is unavailable, use the repair's manual recheck after
the following procedure. The
official Terminal & SSH add-on
mounts /backup writable, which makes it a suitable recovery location:
git -C /config rev-parse --show-toplevel
git -C /config/esphome rev-parse --show-toplevel
git -C /config/esphome status --short
git -C /config/esphome log --oneline -n 10
git -C /config ls-files --stage -- esphome
First make sure ESPHome cannot write version-history data. In the ESPHome
Device Builder Web UI, open the top-right menu, select Settings, enable
Expert Mode under Appearance, and turn off Save version history.
Alternatively, stop ESPHome. Then preserve the inner repository outside
/config:
esphome_backup="/backup/esphome-git-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$esphome_backup"
mv /config/esphome/.git "$esphome_backup/dot-git"
Only when the first check showed mode 160000 for esphome, remove that
Gitlink from the outer index:
git -C /config rm --cached -f -- esphome
Before staging, verify that sensitive and runtime paths are ignored:
git -C /config check-ignore -v --no-index -- \
esphome/secrets.yaml \
esphome/.esphome/ \
esphome/.device-builder.json \
esphome/.device-builder-peer-link-key.bin \
esphome/.receiver_peers.json \
esphome/.offloader_pairings.json
Add missing ignore rules first. Then stage and inspect only the ESPHome path:
git -C /config add -A -- esphome
git -C /config status --short -- esphome
git -C /config ls-files --stage -- esphome
YAML files should have mode 100644; no 160000, secrets.yaml, .esphome/,
key, or pairing files may appear. Commit the verified path, reload
git-ha-ppens, restart ESPHome, and confirm that ESPHome now resolves the parent
work tree:
git -C /config commit -m "fix: track ESPHome configuration in main repository" -- esphome
git -C /config/esphome rev-parse --show-toplevel
The expected final output is /config. If it is /config/esphome again,
esphome/ is usually ignored by the outer repository. Keep the recovery copy
until the remote backup has been verified. Once /config is confirmed, you
may turn Save version history back on if you want ESPHome to create its own
per-save commits in the shared repository.
Repositories excluded by the outer .gitignore do not block git-ha-ppens.
Correctly declared Git submodules are also allowed for compatibility, but
git-ha-ppens does not commit, pull, push, or otherwise manage their contents
recursively.
For manual installations, also verify that the integration directory is named
/config/custom_components/git_ha_ppens; /config/custom_components/githappens
is not the supported component path and is unrelated to the Git collision.
❌ Auto-commit is not triggering
- Verify
auto_commitis enabled in the integration options - The commit interval is a debounce: it starts after the most recent file change
- Check the current
.gitignore; the watcher reloads it automatically, while.gititself is always ignored - Review HA logs for file watcher errors
- If a Git operation was interrupted, git-ha-ppens automatically removes a regular
.git/index.lockafter it has been stale for at least 15 minutes and retries once - If Home Assistant shows an Automatic commits are blocked repair, first make sure no Git process is running, then remove the exact lock path shown in the repair. The repair clears automatically after the next successful check
❌ UI-managed dashboards or settings are not included
Home Assistant stores many UI-managed dashboards and settings in .storage,
which is ignored by default because it can also contain credentials and internal
state. Removing .storage from .gitignore may expose sensitive data. Prefer
YAML-managed dashboards where practical, or review every file carefully before
tracking selected .storage content.
❌ Configuration restore is unavailable or fails
The working tree must be completely clean, including staged, unstaged, and untracked files. Commit or sync wanted changes, discard unwanted tracked changes, and handle remaining untracked files before starting the restore again. Ignored files are not part of the restore and remain untouched.
❌ "Secrets detected" warning
- Review the flagged files and move sensitive values to
secrets.yaml - Ensure
secrets.yamlis listed in.gitignore(it is by default) - The warning is best-effort, runs when the integration loads, and does not block commits or pushes
- If a credential has already been pushed, revoke or rotate it immediately. Adding the file to
.gitignoredoes not remove the credential from existing Git history
❌ The .git directory is much larger than expected
Compare sensor.git_ha_ppens_repo_size with sensor.git_ha_ppens_garbage_size
(both are diagnostic entities on the git-ha-ppens device). A large garbage size
means leftover temporary files from interrupted Git operations, not real
configuration history.
- Run the
git_ha_ppens.gcaction from Developer Tools → Actions, or enable Automatic Git garbage collection under Configure → General Settings. - Git only removes leftovers older than two weeks. Newer leftovers stay until a later run, because they may still belong to a running Git operation.
- If the garbage keeps growing, check which large files are being changed
(for example databases or backup archives) and make sure they are listed in
.gitignore.
git-ha-ppens never runs git gc --prune=now or --aggressive, and never
rewrites history. If a large pack size (not garbage) comes from big files that
were committed in the past, only a manual history rewrite can shrink it, which
git-ha-ppens deliberately does not do.
🤝 Contributing
Contributions are welcome! Whether it's bug reports, feature requests, or pull requests — feel free to get involved.
- 🐛 Bug reports & feature requests: GitHub Issues
- 🔀 Pull requests: Fork, create a branch, and submit a PR
Development Setup
- Clone this repository
- Symlink or copy
custom_components/git_ha_ppensinto your HA dev instance'scustom_components/directory - Restart Home Assistant
- Follow Home Assistant's coding conventions (
ruff,mypy)
📄 License
This project is licensed under the MIT License.
Made with ❤️ for the Home Assistant community
github.com/manuveli/git-ha-ppens
探索相关项目
加载中…