Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concept of bare shared repository in git

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?

like image 895
user2636464 Avatar asked Jun 09 '14 07:06

user2636464


People also ask

What is Git bare and non bare repository?

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 bare repository in Git?

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.

What is create bare repository?

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.

What is -- bare in Git clone?

Git bare clone Just use the –bare switch with the git clone command and you will have a Git repository without a working tree.


1 Answers

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.

like image 109
VonC Avatar answered Sep 17 '22 00:09

VonC