git clone supports several different types of checkouts, notably including --separate-git-dir and --bare.
The former works exactly like a vanilla checkout except the .git directory is located elsewhere than directly in the working tree.
However --bare creates a different kind of repository, significantly it
disables the reflog
and changes the
default refspec for fetch.
Both of these make --bare a poor choice for a repository you intend to develop against, such as via worktrees.
If you just want a "bare" repository directory it is simpler1 to:
- use
--separate-git-dirto write the repository to your desired location- e.g.
git clone --separate-git-dir [repo].git https://github.com/[user]/[repo] - optionally, also pass
--no-checkoutto avoid populating the destination working tree- e.g.
git clone --no-checkout --separate-git-dir [repo].git https://github.com/[user]/[repo]
- e.g.
- e.g.
- delete the working tree that was created
- e.g.
rm -rf [repo]
- e.g.
- release the
master/mainbranch from the working tree we just deleted by swapping to a new--orphanbranch (this doesn't actually create a new branch, it just populatesHEADwith a placeholder name)- e.g.
git --git-dir [repo].git switch --orphan DO_NOT_USE
- e.g.
Footnotes
-
yes, you could edit these configs manually, but you're effectively just redoing
--separate-git-dirby hand ↩