home / skills / terrylica / cc-skills / chezmoi-workflows

This skill helps you back up and sync dotfiles with chezmoi across machines, ensuring drift-free configurations and effortless templated management.

npx playbooks add skill terrylica/cc-skills --skill chezmoi-workflows

Review the files below or copy the command above to add this skill to your agents.

Files (5)
SKILL.md
5.9 KB
---
name: chezmoi-workflows
description: Dotfile backup and sync with chezmoi. TRIGGERS - chezmoi, dotfiles, sync dotfiles, backup configs, cross-machine sync.
allowed-tools: Read, Edit, Bash
---

# Chezmoi Workflows

## When to Use This Skill

Use this skill when:

- Backing up dotfiles to Git repository
- Syncing configuration files across machines
- Tracking changes to shell configs, editor settings, or other dotfiles
- Managing templated configurations with chezmoi
- Troubleshooting dotfile drift between source and target

## Architecture

| Component  | Location                         | Purpose                               |
| ---------- | -------------------------------- | ------------------------------------- |
| **Source** | `$(chezmoi source-path)`         | Git repository with dotfile templates |
| **Target** | `~/`                             | Home directory (deployed files)       |
| **Remote** | GitHub (private recommended)     | Cross-machine sync and backup         |
| **Config** | `~/.config/chezmoi/chezmoi.toml` | User preferences and settings         |

---

## 1. Status Check

```bash
chezmoi source-path                    # Show source directory
chezmoi git -- remote -v               # Show GitHub remote
chezmoi status                         # Show drift between source and target
chezmoi managed | wc -l                # Count tracked files
```

---

## 2. Track File Changes

After editing a config file, add it to chezmoi:

```bash
chezmoi status                         # 1. Verify file shows as modified
chezmoi diff ~/.zshrc                  # 2. Review changes
chezmoi add ~/.zshrc                   # 3. Add to source (auto-commits if configured)
chezmoi git -- log -1 --oneline        # 4. Verify commit created
chezmoi git -- push                    # 5. Push to remote
```

---

## 3. Track New File

Add a previously untracked config file:

```bash
chezmoi add ~/.config/app/config.toml  # 1. Add file to source
chezmoi managed | grep app             # 2. Verify in managed list
chezmoi git -- push                    # 3. Push to remote
```

---

## 4. Sync from Remote

Pull changes from GitHub and apply to home directory:

```bash
chezmoi update                         # 1. Pull + apply (single command)
chezmoi verify                         # 2. Verify all files match source
chezmoi status                         # 3. Confirm no drift
```

---

## 5. Push All Changes

Bulk sync all modified tracked files to remote:

```bash
chezmoi status                         # 1. Review all drift
chezmoi re-add                         # 2. Re-add all managed files (auto-commits)
chezmoi git -- push                    # 3. Push to remote
```

---

## 6. First-Time Setup

### Install chezmoi

```bash
brew install chezmoi                   # macOS
```

### Initialize (fresh start)

```bash
/usr/bin/env bash << 'CONFIG_EOF'
chezmoi init                           # Create empty source
chezmoi add ~/.zshrc ~/.gitconfig      # Add first files
gh repo create dotfiles --private --source="$(chezmoi source-path)" --push
CONFIG_EOF
```

### Initialize (clone existing)

```bash
chezmoi init [email protected]:<user>/dotfiles.git
chezmoi apply                          # Deploy to home directory
```

---

## 7. Configure Source Directory

Move source to custom location (e.g., for multi-account SSH):

```bash
/usr/bin/env bash << 'SKILL_SCRIPT_EOF'
mv "$(chezmoi source-path)" ~/path/to/dotfiles
SKILL_SCRIPT_EOF
```

Edit `~/.config/chezmoi/chezmoi.toml`:

```toml
sourceDir = "~/path/to/dotfiles"
```

Verify:

```bash
chezmoi source-path                    # Should show new location
```

---

## 8. Change Remote

Switch to different GitHub account or repository:

```bash
chezmoi git -- remote -v                                              # View current
chezmoi git -- remote set-url origin [email protected]:<user>/<repo>.git # Change
chezmoi git -- push -u origin main                                    # Push to new remote
```

---

## 9. Resolve Merge Conflicts

```bash
/usr/bin/env bash << 'GIT_EOF'
chezmoi git -- status                  # 1. Identify conflicted files
chezmoi git -- diff                    # 2. Review conflicts
# Manually edit files in $(chezmoi source-path)
chezmoi git -- add <resolved-files>    # 3. Stage resolved files
chezmoi git -- commit -m "Resolve merge conflict"
chezmoi apply                          # 4. Apply to home directory
chezmoi git -- push                    # 5. Push resolution
GIT_EOF
```

---

## 10. Validation (SLO)

After major operations, verify system state:

```bash
chezmoi verify                         # Exit 0 = all files match source
chezmoi diff                           # Empty = no drift
chezmoi managed                        # Lists all tracked files
chezmoi git -- log --oneline -3        # Recent commit history
```

---

## Reference

- [Setup Guide](./references/setup.md) - Installation, multi-account GitHub, migration
- [Prompt Patterns](./references/prompt-patterns.md) - Detailed workflow examples
- [Configuration](./references/configuration.md) - chezmoi.toml settings, templates
- [Secret Detection](./references/secret-detection.md) - Handling detected secrets

**Chezmoi docs**: <https://www.chezmoi.io/reference/>

---

## Troubleshooting

| Issue              | Cause                      | Solution                                     |
| ------------------ | -------------------------- | -------------------------------------------- |
| chezmoi not found  | Not installed              | Install via `brew install chezmoi`           |
| Source path empty  | Not initialized            | Run `chezmoi init`                           |
| Git remote not set | Missing GitHub repo        | Run `chezmoi git -- remote add origin URL`   |
| Apply fails        | Template error             | Check template syntax with `chezmoi diff`    |
| Merge conflicts    | Diverged source and target | Use `chezmoi merge` to resolve               |
| Secrets detected   | Plain text credentials     | Use chezmoi templates with 1Password/Doppler |

Overview

This skill provides a practical chezmoi workflow for backing up, tracking, and syncing dotfiles across machines using a Git-backed chezmoi source. It codifies common commands and sequences for status checks, adding files, pushing changes, pulling updates, and resolving conflicts. The goal is predictable cross-machine configuration management and safe recovery of personal config state.

How this skill works

The skill inspects the chezmoi source directory, the managed target files in the home directory, and the Git remote used for cross-machine sync. It sequences core chezmoi commands (status, add, update, apply, verify) and Git operations to capture edits, push commits to a remote repo, and pull/apply updates on other machines. It also covers initialization, changing source location or remote, and conflict resolution workflows.

When to use it

  • Backing up local dotfiles to a Git repository
  • Syncing shell, editor, and app configs between machines
  • Onboarding a new machine with your curated dotfiles
  • Tracking templated configurations managed by chezmoi
  • Diagnosing and resolving drift between source and deployed files

Best practices

  • Keep the chezmoi source in a private Git repo for sensitive configs
  • Run chezmoi status and chezmoi diff before commits or pushes
  • Use chezmoi add immediately after editing important config files to record intent
  • Automate periodic pushes or CI checks to ensure remote backups are fresh
  • Run chezmoi verify after major updates to confirm target matches source

Example use cases

  • Quickly add a changed ~/.zshrc to source, commit, and push for cross-machine availability
  • Clone your dotfiles repo on a new laptop and run chezmoi apply to deploy your environment
  • Bulk-sync modified tracked files after a maintenance session using re-add and git push
  • Recover from accidental local edits by running chezmoi update and verify to restore source state
  • Resolve merge conflicts in chezmoi source, commit the resolution, and apply changes to the home directory

FAQ

What if chezmoi is not installed?

Install via your platform package manager (example: brew install chezmoi on macOS) and then initialize or clone a source repo.

How do I move the source directory to a custom location?

Move the directory, update sourceDir in ~/.config/chezmoi/chezmoi.toml, and verify with chezmoi source-path.

How do I handle secrets in dotfiles?

Avoid plain-text secrets. Use chezmoi templates with a secret manager (1Password, Doppler) or encrypted storage and validate with secret-detection tooling.