Skip to main content
The init command sets up the source directory, optionally clones a repository, generates the config file, and optionally applies the changes to your system.

Usage

chezmoi init [repo]

Description

The init command performs the following steps in order:
  1. Initialize the source directory - If chezmoi does not detect a Git repository in the source directory, chezmoi will clone the provided repo into the source directory. If no repo is provided, chezmoi will initialize a new Git repository.
  2. Generate config file - If the initialized source directory contains a .chezmoi.$FORMAT.tmpl file, a new configuration file will be created using that file as a template.
  3. Apply changes (if --apply is set) - Run chezmoi apply to update the destination directory.
  4. Purge (if --purge is set) - Remove the source, config, and cache directories.
  5. Purge binary (if --purge-binary is set) - Attempt to remove the chezmoi binary itself.

Repository URL Guessing

By default, if a repo argument is given, chezmoi will guess the full git repo URL using HTTPS (or SSH with --ssh), according to these patterns:
PatternHTTPS RepoSSH Repo
userhttps://github.com/user/dotfiles.git[email protected]:user/dotfiles.git
user/repohttps://github.com/user/repo.git[email protected]:user/repo.git
site/user/repohttps://site/user/repo.gitgit@site:user/repo.git
sr.ht/~userhttps://git.sr.ht/~user/dotfiles[email protected]:~user/dotfiles
sr.ht/~user/repohttps://git.sr.ht/~user/repo[email protected]:~user/repo
To disable URL guessing, use --guess-repo-url=false.

Flags

-a, --apply
boolean
default:"false"
Run chezmoi apply after checking out the repo and creating the config file.
--branch
string
Check out the specified branch instead of the default branch.
-C, --config-path
path
Write the generated config file to the specified path instead of the default location.
--data
boolean
default:"true"
Include existing template data when creating the config file. Set to false to simulate creating the config file with no existing template data.
-d, --depth
integer
Clone the repo with the specified depth (creates a shallow clone).
--git-lfs
boolean
default:"false"
Run git lfs pull after cloning the repo.
-g, --guess-repo-url
boolean
default:"true"
Guess the repo URL from the repo argument.
--one-shot
boolean
default:"false"
Equivalent to --apply --depth=1 --force --purge --purge-binary. Attempts to install your dotfiles with chezmoi and then remove all traces of chezmoi from the system. Useful for temporary environments like Docker containers.
-p, --purge
boolean
default:"false"
Remove the source and config directories after applying.
-P, --purge-binary
boolean
default:"false"
Attempt to remove the chezmoi binary after applying.
--recurse-submodules
boolean
default:"true"
Recursively clone submodules.
--ssh
boolean
default:"false"
Guess an SSH repo URL instead of an HTTPS repo URL.
-x, --exclude
types
Exclude entry types (comma-separated: dirs, files, remove, scripts, symlinks, always, encrypted, externals, templates).
-i, --include
types
Include only specified entry types (comma-separated: dirs, files, remove, scripts, symlinks, always, encrypted, externals, templates).

Examples

Initialize from a GitHub user’s dotfiles repository

chezmoi init username

Initialize and apply immediately

chezmoi init username --apply

Initialize and purge afterwards

chezmoi init username --apply --purge

Initialize from a specific repository

chezmoi init user/dots

Initialize from GitLab or other providers

chezmoi init gitlab.com/user
chezmoi init codeberg.org/user

One-shot mode for Docker containers

chezmoi init username --one-shot
This will clone your dotfiles, apply them, and remove chezmoi completely.

Notes

If you’re using a different version control system (not Git), you’ll need to manually create the source directory structure. To prevent chezmoi from trying to clone or create a Git repository, add an empty .git directory:
mkdir -p ~/.local/share/chezmoi/.git
  • apply - Apply changes after initialization
  • update - Pull and apply changes from the repository

Build docs developers (and LLMs) love