I have been facing difficulty in understanding the bare repository . I have read everywhere that a shared repo is a bare repo. Why must it be a bare repo? Can't it be a normal repo which collaborators clone and then push/pull?
A bare repository is one that contains nothing but the . git folder; in other words, it has the index but lacks the actual working files. A non-bare repository is what you're used to working with, which includes both the git index and the checked out copy of working files.
What is a bare repository? A bare repository is the same as default, but no commits can be made in a bare repository. The changes made in projects cannot be tracked by a bare repository as it doesn't have a working tree. A working tree is a directory in which all the project files/sub-directories reside.
A bare repository is one in which local development is not allowed. This type of repository is useful if you are setting up a server to host your source code or perhaps implementing a backup strategy that replicates your source code to a safe, off-site location.
Git bare clone Just use the –bare switch with the git clone command and you will have a Git repository without a working tree.
It needs to be a bare repo because a not bare repo would have a working tree (meaning a specific version of that repo checked out and with files visible).
Each time you are pushing to a non-bare repo, you have no guarantee that its working tree will reflect what you are pushing, since by default said working tree will be untouched.
(Imagine if a push would trigger an update of the working tree: the files would change all of a sudden without any control from users on the receiving end)
That is why it is simpler to have a bare repo as an upstream repo (one you push to): no working tree to manage/update.
See more at "all about "bare" repos -- what, why, and how to fix a non-bare push".
It doesn't have a checked out tree, so it just does what the "server" notionally does in a centralised VCS -- records commits, branches, etc when you push to it, and gives you the latest versions when you clone or pull from it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With