Git checkout from read-only bare repo

I have bare git repositories owned by one user. I want to extract the work tree from one of those while running as another user who does not have write permission to the git repo.

git --no-optional-locks --git-dir=/path/to/bare-repo.git --work-tree=. checkout -f

or

git --no-optional-locks --git-dir=/path/to/bare-repo.git --work-tree=. reset HEAD --hard

but in each case git wants to be able to write to lock files in the bare repo directory which the current user doesn't have permission for.

Is there any deep "plumbing" command that can pull out files without needing to lock or write to any part of the repo?

I realize I could create a second repo owned by the current user and pull into it, but that results in a lot of copying for no reason and I'd like to avoid that.

-- UPDATE --

My understanding of the problem was incomplete. I wanted to be able to run the checkout against the existing directory and only copy the files which had changed, i.e. with git's usual efficiency. However git needs the mtime of the checked-out files for that, and the mtime isn't stored in the objects, it is stored in the index. So, to get the efficiency I wanted, there needs to be a writable index.

I still didn't want .git/ files in the working tree checkout, but I got what I wanted by git clone -s into a persistent third location owned by the second user, and then my command above, but referencing this git repo instead of the original, and referencing a specific commit instead of a named branch (so that I don't have to sync branch references from origin to clone).

1

1 Answer

Use git clone -s. This will set up a writable repository which references the original repository's object store, so it will have a working tree index but won't store any objects of its own.

git clone --shared /path/to-bare-repo.git .

There are 'plumbing' commands to get contents of individual files and trees, but not to check out a whole working tree, as it's kind of a 'porcelain'-level feature in itself.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like