AI coding tools are great, but there's a non-zero chance one of them nukes your .git folder someday. Scheduled backups work, but I wanted something that just happens automatically โ€” so I set up a bare repository on a separate drive that syncs on every commit via a post-commit hook. Here's how. (macOS, but Linux is identical.) Pick somewhere outside your project โ€” an external drive works well. mkdir -p /path/to/backup/project.git cd /path/to/backup/project.git git init --bare

A bare repo stores only history, no working files. Same format GitHub uses internally. cd ~/path/to/project

git remote add backup /path/to/backup/project.git

# Initial push (check your branch name first) git branch --show-current git push backup <branch-name>

# Verify git ls-remote backup

touch .git/hooks/post-commit chmod +x .git/hooks/post-commit

.git/hooks/post-commit: #!/bin/sh current_branch=$(git rev-parse --abbrev-ref HEAD) git push backup "$current_branch" --quiet >/dev/null 2>&1 &

The & runs it in the background so commits don't feel any slower. touch backup_test.txt git add backup_test.txt git commit -m "test: post-commit hook"

Then compare hashes: git log --oneline -1 git ls-remote backup

If main points to the same hash in both, you're good. Clean up: git rm backup_test.txt git commit -m "chore: remove test file"

If only .git was deleted (files intact): cd /path/to/project git init git remote add backup /path/to/backup/project.git git fetch backup git branch -r # confirm branch name git reset --mixed backup/<branch-name> git status # commit any remaining diff

If the whole folder is gone: git clone /path/to/backup/project.git my_project

In both cases, re-add the post-commit hook afterward since .git/hooks/ isn't tracked by Git. That's it. A bit of setup, but once it's running you don't think about it again.