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-dir
to 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-checkout
to 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
/main
branch from the working tree we just deleted by swapping to a new--orphan
branch (this doesn't actually create a new branch, it just populatesHEAD
with 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-dir
by hand ↩