Version Controlling Your Smart Home: Mastering Home Assistant Configuration with Git
- #Home_Assistant
- #Git
- #Configuration_Management
- #Smart_Home
- #Automation
- #Best_Practices

Why Use Git for Home Assistant Configuration?
Your Home Assistant configuration, encompassing automations, scripts, dashboards, integrations, and helpers, is the brain of your smart home. As your setup grows, managing changes, tracking what broke when, rolling back unwanted modifications, and recovering from disasters becomes increasingly complex. This is where Git, a powerful version control system, becomes invaluable.
Using Git allows you to:
- Track Every Change: See exactly who changed what and when.
- Roll Back Mistakes: Easily revert to a previous working state if an update or configuration change breaks something.
- Experiment Safely: Create branches to test new features or significant changes without affecting your live system.
- Simplify Migration & Recovery: Quickly set up a new Home Assistant instance by simply cloning your repository.
- Collaborate (Optional): If you work on your config with others, Git makes merging changes straightforward.
- Off-site Backups: Pushing your configuration to a remote repository provides an easily accessible off-site backup.
While Home Assistant's built-in backup feature is essential for full system recovery, Git complements it by providing granular control and history specifically for your configuration files.
Prerequisites
Before you begin, you'll need:
- Access to your Home Assistant configuration directory (e.g., via Samba Share, SSH, or the File Editor add-on).
- Git installed on the machine where you will be interacting with the files. If accessing via SSH into the Home Assistant OS/Supervised environment, Git is usually available. If editing files via Samba from another computer, you'll need Git installed on that computer.
- Basic familiarity with command line interfaces.
Setting Up Your Home Assistant Config Repository
1. Navigate to Your Configuration Directory
Using your preferred method (SSH terminal is recommended for direct access), navigate to your Home Assistant configuration directory. This is typically the directory containing configuration.yaml
, automations.yaml
, scripts.yaml
, custom_components
, lovelace
directories, etc.
cd /path/to/your/homeassistant/config
2. Initialize the Git Repository
Initialize a new Git repository in this directory:
git init
This creates a hidden .git
directory, which Git uses to store its history and tracking information.
3. Create a .gitignore File
This is a critical step. You *must* tell Git to ignore files that are sensitive, temporary, or automatically generated. The most important file to ignore is secrets.yaml
, as it contains passwords, API keys, and other sensitive information that should NEVER be committed to a Git repository (especially a public one!). You should also ignore database files, log files, and cache directories.
Create a file named .gitignore
in your configuration directory and add the following lines (adjusting based on your specific setup):
# Sensitive files
secrets.yaml
# Database and related files
*.db
*.db-wal
*.db-shm
# Log files
home-assistant.log
*.log
# Cache and temporary files
__pycache__/
.pytest_cache/
.storage/
devtools_json_cache.json
zigbee.db # If using ZHA
zwcfg_*.xml # If using Z-Wave (old style)
.
# Add other specific files or directories you want to ignore
# e.g., specific custom component caches, large media files, etc.
Make sure secrets.yaml
is definitely in this file.
4. Add Your Configuration Files
Now, add all files and directories in your configuration that are not ignored by .gitignore
to the staging area:
git add .
The .
tells Git to add all changes in the current directory and its subdirectories.
5. Make Your First Commit
Commit the staged files to your repository's history. This creates the initial snapshot of your configuration.
git commit -m "Initial commit of Home Assistant configuration"
Congratulations! Your Home Assistant configuration is now under Git version control.
Your Daily Git Workflow
As you make changes to your Home Assistant configuration (adding devices, writing automations, tweaking dashboards), you should follow a simple Git workflow:
1. Check Status (Optional but Recommended)
See which files have been modified, added, or deleted since your last commit:
git status
2. Stage Changes
Add the files you've changed and want to include in your next commit to the staging area. You can add specific files or use git add .
again to stage all changes (be careful with git add .
if you have files you don't intend to track).
git add configuration.yaml automations.yaml scenes.yaml
# Or stage all changes
git add .
3. Commit Changes
Commit the staged changes with a descriptive message explaining what you did:
git commit -m "Added new motion sensor automation"
# Or for multiple lines
git commit -m "Refactored living room lights automation
- Added conditional brightness adjustment
- Cleaned up trigger logic"
Committing frequently with clear messages makes it much easier to track changes and revert if needed.
Using a Remote Repository (Recommended)
Storing your Git repository only locally protects against accidental deletions or errors but doesn't help if the storage medium fails. Pushing your repository to a remote hosting service (like GitHub, GitLab, Bitbucket) or a self-hosted Git server provides an off-site backup and allows access from other machines.
1. Create a New, Empty Remote Repository
Go to your chosen Git hosting service (GitHub, GitLab, etc.) and create a new, empty repository. Make sure it is set to PRIVATE, especially if you might accidentally commit something sensitive despite your .gitignore
. Do NOT initialize it with a README or license file if your local repo already has commits.
2. Add the Remote to Your Local Repository
In your Home Assistant config directory, add the remote repository URL. The URL will be provided by your hosting service (e.g., https://github.com/yourusername/hass-config.git
or [email protected]:yourusername/hass-config.git
).
git remote add origin https://github.com/yourusername/your-repo-name.git
origin
is the conventional name for the primary remote.
3. Push Your Local Commits to the Remote
Push your local commits to the remote repository. The -u
flag sets the upstream branch, so future git push
and git pull
commands are simpler.
git push -u origin main # or master, depending on your branch name
Keeping Remote Updated
After making local commits, regularly push them to your remote:
git push
Restoring or Rolling Back Changes
Viewing History
See the history of your commits:
git log
Each commit has a unique hash (e.g., a1b2c3d4
). Note the hash of the commit you want to revert to.
Rolling Back a Specific File
If a change to a single file caused issues, you can revert just that file to a previous commit's state:
git checkout a1b2c3d4 configuration.yaml
Replace a1b2c3d4
with the commit hash and configuration.yaml
with the file path.
Reverting to a Previous Commit (Discarding Later Changes)
To completely reset your configuration to a previous state, discarding all subsequent commits:
git reset --hard a1b2c3d4
Use git reset --hard
with caution, as it permanently discards changes.
Restoring on a New System
On a new Home Assistant installation, after setting up SSH access, simply navigate to the configuration directory and clone your repository (after removing the default files, but *be careful* not to delete anything critical HA needs):
cd /path/to/homeassistant/config
git clone https://github.com/yourusername/your-repo-name.git .
The .
at the end clones into the current directory. You will then need to manually recreate your secrets.yaml
file with your sensitive data (which is why not committing it is crucial for security and portability).
Best Practices for Managing Your Home Assistant Config with Git
- Commit Frequently: Make small, focused commits with clear messages. Instead of one giant commit for a week's worth of changes, commit after adding a single device or completing one automation.
- Write Meaningful Commit Messages: A good message explains why you made the change, not just what you changed. This helps tremendously when looking back through history.
- NEVER Commit Secrets: Seriously, double-check your
.gitignore
and usegit status
before committing. Passwords, API keys, and sensitive tokens don't belong in your history. - Use a Private Remote: If using a cloud hosting service, always make your Home Assistant config repository private.
- Regularly Push to Remote: Treat your remote repository as your off-site backup. Push your changes regularly.
- Consider Branching: For major overhauls or experimental setups, create a new branch (e.g.,
develop
,testing-new-lights
). Merge back to your main branch only when stable. - Test Rollbacks: Periodically practice reverting a file or two in a test environment (if possible) or understand the commands well before you need them in an emergency.
Conclusion
Integrating Git into your Home Assistant workflow provides a robust safety net and a clear history of your smart home's evolution. While it adds an initial setup step and requires a command-line interface, the ability to track changes, easily roll back errors, and simplify recovery is invaluable for anyone serious about maintaining a reliable and complex Home Assistant setup. Start small, commit often, and protect your secrets, and you'll gain confidence in managing your smart home configuration.

NGC 224
Author bio: