Fake bare git repos

martin f krafft madduck at madduck.net
Wed Apr 6 11:10:24 CEST 2011

also sprach Richard Hartmann <richih.mailinglist at gmail.com> [2011.04.02.2203 +0200]:
> Can someone dump a current snippet that will create a fake bare
> git repo that works locally _and_ allows me to push to a truly
> bare remote?

The concept of "fake bare git" comes from the fact that the GIT_DIR
is names e.g. vim.git (instead of .git), which is like a bare repo,
but core.bare is set to false (hence "fake"), because there is
a worktree, albeit it's detached.

I think "detached worktree repository" also covers it and might be
a better name.

Here is how to create one:

Create a *non-bare* repo as you would always do, but in a temp
directory (or directly in ~ if you wish):

  mkdir mytempworktree && cd mytempworktree
  git init
  git remote add origin ssh://server/path/to/repo
  git config branch.master.remote origin
  git config branch.master.merge refs/heads/master

Or if the repo already exists remotely, clone it into a temp
directory (or ~):

  mkdir mytempworktree && cd mytempworktree
  git clone git://git.madduck.net/madduck/pub/etc/vim.git

Then move the GIT_DIR to the final location and set core.worktree
to point to the worktree (~ in our case)

  git config core.worktree ../../     # ~/.fgits/vim.git/../../ → ~
  mv .git ~/.fgits/vim.git

and possibly move checked out files to the worktree:

  mv * .* ~

To work with the repo, make sure to export


    alias git="git --work-tree=$HOME --git-dir=$HOME/.fgits/repo.git")

Essentially, this is what my vcsh function does for me:


martin | http://madduck.net/ | http://two.sentenc.es/
"glaube heißt nicht wissen wollen, was wahr ist."
                                                 - friedrich nietzsche
spamtraps: madduck.bogus at madduck.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 1124 bytes
Desc: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)
URL: <http://lists.madduck.net/pipermail/vcs-home/attachments/20110406/d8234a80/attachment.pgp>

More information about the vcs-home mailing list