Push results in message about HEAD ref not existing
Running the following command:
$ git push git@ConnectorHost:gD1/repo8 main
results in:
Counting objects: 3, done. Writing objects: 100% (3/3), 226 bytes \| 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: HEAD ref is "refs/heads/master", but this ref does not exist. remote: Consider asking the admin for repo "gD1/repo8.git" remote: to set its default branch to a valid ref so that remote: "git clone" and "git checkout" can check out remote: without specifying a branch name. To [email protected]:repo/grepo1 * [new branch] main -> main
To resolve this issue, do one of the following:
- Edit the repo spec to specify
refs/heads/main
as the default branch to clone from. This is required for any project not using therefs/heads/master
default branch. For details, see Specify a default branch. -
Run the following special command to set the default branch to
refs/heads/main
:$ git clone git@ConnectorHost:@defaultbranch:gD1/repo8=refs/heads/main
This results in the following output:
git clone git@ConnectorHost:@defaultbranch:gD1/repo8=refs/heads/main Cloning into 'main'... repo='gD1/repo8', old DefaultBranch='', new DefaultBranch='refs/heads/main' fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
NoteBecause the special command is not standard Git syntax, Git cannot parse it and the command terminates with:
Fatal: Could not read from remote repository.
You can also run
@defaultbranch:gD1/repo8
to show the default branch and@defaultbranch:gD1/repo8=
to clear the default branch.