Concurrency in a GIT repo on a network shared folder Concurrency in a GIT repo on a network shared folder linux linux

Concurrency in a GIT repo on a network shared folder


Git requires minimal file locking, which I believe is the main cause of problems when using this kind of shared resource over a network file system. The reason it can get away with this is that most of the files in a Git repo--- all the ones that form the object database--- are named as a digest of their content, and immutable once created. So there the problem of two clients trying to use the same file for different content doesn't come up.

The other part of the object database is trickier-- the refs are stored in files under the "refs" directory (or in "packed-refs") and these do change: although the refs/* files are small and always rewritten rather than being edited. In this case, Git writes the new ref to a temporary ".lock" file and then renames it over the target file. If the filesystem respects O_EXCL semantics, that's safe. Even if not, the worst that could happen would be a race overwriting a ref file. Although this would be annoying to encounter, it should not cause corruption as such: it just might be the case that you push to the shared repo, and that push looks like it succeeded whereas in fact someone else's did. But this could be sorted out simply by pulling (merging in the other guy's commits) and pushing again.

In summary, I don't think that repo corruption is too much of a problem here--- it's true that things can go a bit wrong due to locking problems, but the design of the Git repo will minimise the damage.

(Disclaimer: this all sounds good in theory, but I've not done any concurrent hammering of a repo to test it out, and only share them over NFS not CIFS)


Why bother? Git is designed to be distributed. Just have a repository on each machine and use the publish and pull mechanism to propagate your changes between them.

For backup purposes, run a nightly task to copy your repository to the share.

Or, create one repository each on the share and do your work from them but use them as distributed repositories from which you can pull changesets from each other. If you use this method, then performance of doing builds and so on will be decreased since you will be constantly accessing over the network.

Or, have distributed repositories on your own computers, and run a periodic task to push your commits to the repositories on the share.


Apparently using a central git repo is supported. Most prescribed uses indicate ssh or http access, neither of which avoid the simultaneous access to the repo. Even if you are doing completely distributed usage, this question arises if more than two collaborators push to the same repo anywhere. So far, no response has answered the question. Does the design of git allows it to handle N simultaneous pushes to a branch?