Skip to content

Instantly share code, notes, and snippets.

@dimo414
Created July 23, 2025 06:48
Show Gist options
  • Save dimo414/ee248152d3a634e6291f69d19f28b8b2 to your computer and use it in GitHub Desktop.
Save dimo414/ee248152d3a634e6291f69d19f28b8b2 to your computer and use it in GitHub Desktop.
Difference between a standard or --separate-git-checkout repo and a --bare repo

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:

  1. 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]
  2. delete the working tree that was created
    • e.g. rm -rf [repo]
  3. 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 populates HEAD with a placeholder name)
    • e.g. git --git-dir [repo].git switch --orphan DO_NOT_USE

Footnotes

  1. yes, you could edit these configs manually, but you're effectively just redoing --separate-git-dir by hand

$ diff -u standard/repo/.git/config bare/repo.git/config
--- standard/repo/.git/config 2025-07-22 23:05:22.038583257 -0700
+++ bare/repo.git/config 2025-07-22 23:05:41.634577229 -0700
@@ -1,11 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
- bare = false
- logallrefupdates = true
+ bare = true
[remote "origin"]
url = https://github.com/my/repo.git
- fetch = +refs/heads/*:refs/remotes/origin/*
-[branch "master"]
- remote = origin
- merge = refs/heads/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment