A bare repository in git does not include a checkout. So in order to set the default branch that users will get after they clone, you cannot use git-checkout mybranch.
Instead, if you want the default branch to be something other than master
, you need to do this:
git symbolic-ref HEAD refs/heads/mybranch
Which will update the HEAD
file in your repository so that it contains:
ref: refs/heads/mybranch
This is well documented in the git-symbolic-ref
manpage but it's not necessarily the first place you'd think of looking.
Yes, in the bare repo.
Thanks for the tip.
This also works in a checkout worktree.
I have an obscure usecase:
If you need to clone a repo and you can't control the checkout branch (because you are using another tool that assumes the default branch), you can still control which branch will be checked out on clone.