Files
heartwood/crates/radicle-cli/examples/rad-init-detached-head.md
T
Sekhat Temporus 37ea81766e cli: improve default branch pick
When using `rad init` the default branch for the project can be predetermined by
inspecting the working copy repository.

To improve the experience, it will first check `init.defaultBranch` in the Git
configuration file.

If it does not find this, it falls back to choosing the default head of the
repository at the time. This may be HEAD, and in this case it will error and
provide helpful information.

The repository may also not have any default head at the time, and this also
results in an error and hint.
2025-07-23 07:43:27 +01:00

955 B

Let's assume you created a Git repository containing two commits and checked out the first one, leaving you in a detached HEAD state:

$ git init -q
$ touch file1.txt
$ git add .
$ git commit -m "Create file" -q
$ touch file2.txt
$ git add .
$ git commit -m "Create a second file" -q
$ git checkout HEAD~1

If you try to rad init the repository in this state, it will attempt to determine a default branch. However, it cannot because we are currently not on any branch nor have we set the init.defaultBranch option in our git config.

Using rad init will fail, providing a hint on how to fix the issue:

$ rad init
✗ Error: in detached HEAD state
✗ Hint: try `git checkout <default branch>` or set `git config set --local init.defaultBranch <default branch>`
✗ Error: aborting `rad init`

Alternatively, if you know a branch that already exists, and you would like to use, you can use the --default-branch option.