On Thu, 23 Jul 2015 00:54:32 -0700 (PDT)
dexter ietf <dexter.i...@gmail.com> wrote:

> bare repository only contains the meta data, but when i clone from a 
> bare-repo
> full tree will be checked out. how does git manage to achieve that. i
> know it's
> a newbie question. but surprised by the fact that git can do that. so 
> curious to
> know the answer asap. thanks.

I'm afraid you again have certain terminology troubles with Git ;-)
Bare repositories contain *data* -- all the history of the project they
manage.  And so do "normal" repositories -- just in a slightly
different way.

A "normal" repository -- that one you're typically work with --
consists of the three things:

* The Git database (object storage + configuration);
* The index (the staging area);
* The work tree.

While the locations of all these tree components can be changed in
different ways, by default, these are located like this:

* The work tree is a directory which contains the files checked
  out.
* The Git database is the directory named ".git" immediately under
  the work tree.
* The index is a file named "index" located in the ".git" directory.

Now notice that while this layout suggests the work tree is somehow the
"main thing", this is wrong: most of the time the work tree mostly
contains versions of files already kept in the Git database.  IOW,
the only things missing in the Git database compared to the work tree
are unstaged changes and untracked files.  To put it in another
perspective, if you have a Git database you can always create a work
tree out of it -- simply by checking out files from certain commit in
that database, but the reverse it not true: the work tree does not
contain any history -- just a slice of it plus local modifications, if
any.

A bare repository is basically what's contained in the ".git" directory
of a "regular" repository except for the index (bare repositories do
not need to have index because it would be of no use).  That's why
there's a convention of giving directories of bare repositories names
ending in ".git" -- to underline that they are what ".git" is to
regular repos.

As to cloning, when you just do `git clone`, no matter if you're
cloning a regular or a bare repository, Git assumes you want to get a
regular repository as a result (you can override this by passing
"--bare" to `git clone`).  That's because both kinds of repositories
contain the same structure of their databases so there's no difference
when cloning.

Now the most technical detail: when running `git clone` without
"--bare", you can tell Git which branch you'd like to check out using
the "--branch" option.  If you won't do that, Git will pick the branch
to wich the HEAD reference points in the source repository.  In most
cases it points to "master", so that's what you typically get checked
out.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to