assets/chezmoi.io/docs/reference/commands/init.md
init [repo]Setup the source directory, generate the config file, and optionally update the destination directory to match the target state. This is done in the following order:
The source directory is initialized. 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.
If the initialized source directory contains a .chezmoi.$FORMAT.tmpl file,
a new configuration file will be created using that file as a template.
If the --apply flag is provided, chezmoi apply is run.
If the --purge flag is provided, chezmoi will remove the source, config,
and cache directories.
If the --purge-binary is passed, chezmoi will attempt to remove its own
binary.
By default, if repo is given, chezmoi will guess the full git repo URL, using
HTTPS by default, or SSH if the --ssh option is specified, according to the
following patterns:
| Pattern | HTTPS Repo | SSH repo |
|---|---|---|
user | https://[email protected]/user/dotfiles.git | [email protected]:user/dotfiles.git |
user/repo | https://[email protected]/user/repo.git | [email protected]:user/repo.git |
site/user/repo | https://user@site/user/repo.git | git@site:user/repo.git |
sr.ht/~user | https://[email protected]/~user/dotfiles | [email protected]:~user/dotfiles.git |
sr.ht/~user/repo | https://[email protected]/~user/repo | [email protected]:~user/repo.git |
To disable git repo URL guessing, pass the --guess-repo-url=false option.
!!! info
If you are using a different version control system, there are different
steps [required for repo initialization][alt-vcs]. To prevent chezmoi from
trying to clone or create a Git repository, add an empty `.git` directory to
the source directory.
```sh
mkdir -p ~/.local/share/chezmoi/.git
```
--8<-- "config-format.md"
-a, --applyRun chezmoi apply after checking out the repo and creating the config file.
--branch branchCheck out branch instead of the default branch.
-C, --config-path pathWrite the generated config file to path instead of the default location.
--data boolInclude existing template data when creating the config file. This defaults to
true. Set this to false to simulate creating the config file with no
existing template data.
-d, --depth depthClone the repo with depth depth.
--git-lfs boolRun git lfs pull after cloning the repo.
-g, --guess-repo-url boolGuess the repo URL from the repo argument. This defaults to true.
--one-shot--one-shot is the equivalent of --apply, --depth=1, --force, --purge,
and --purge-binary. It attempts to install your dotfiles with chezmoi and then
remove all traces of chezmoi from the system. This is useful for setting up
temporary environments (e.g. Docker containers).
--promptForce the prompt*Once template functions to prompt.
--promptBool pairsPopulate the promptBool template function with values from pairs. pairs is
a comma-separated list of prompt=value pairs. If promptBool is called
with a prompt that does not match any of pairs, then it prompts the user for
a value.
--promptChoice pairsPopulate the promptChoice template function with values from pairs. pairs
is a comma-separated list of prompt=value pairs. If promptChoice is
called with a prompt that does not match any of pairs, then it prompts the
user for a value.
--promptDefaultsMake all prompt* template function calls with a default value return that
default value instead of prompting.
--promptInt pairsPopulate the promptInt template function with values from pairs. pairs is
a comma-separated list of prompt=value pairs. If promptInt is called
with a prompt that does not match any of pairs, then it prompts the user for
a value.
--promptMultichoice pairsPopulate the promptMultichoice template function with values from pairs.
pairs is a comma-separated list of prompt=value[/value] pairs. If
promptMultichoice is called with a prompt that does not match any of
pairs, then it prompts the user for values.
--promptString pairsPopulate the promptString template function with values from pairs. pairs
is a comma-separated list of prompt=value pairs. If promptString is
called with a prompt that does not match any of pairs, then it prompts the
user for a value.
-p, --purgeRemove the source and config directories after applying.
-P, --purge-binaryAttempt to remove the chezmoi binary after applying.
--recurse-submodules boolRecursively clone submodules. This defaults to true.
--sshGuess an SSH repo URL instead of an HTTPS repo.
-x, --exclude types--8<-- "common-flags/exclude.md"
-i, --include types--8<-- "common-flags/include.md"
chezmoi init user
chezmoi init user --apply
chezmoi init user --apply --purge
chezmoi init user/dots
chezmoi init codeberg.org/user
chezmoi init gitlab.com/user