# .git and retrieving full source tree for own project(s)

3 messages from 2009-09-04 to 2009-09-04. Participants: armencho@gmail.com, Junio C Hamano.
Thread: https://gitlist.dev/t/20855

## armencho@gmail.com, 2009-09-04 19:52

Subject: .git and retrieving full source tree for own project(s)
Message-ID: <981b72360909041252i29551a5chb8b3a2a5c6444ee3@mail.gmail.com>
URL: https://gitlist.dev/e/981b72360909041252i29551a5chb8b3a2a5c6444ee3%40mail.gmail.com

```
Hi all,

I just started with git and suprisingly or unsurprisingly everything
works, and I love it. I had been working on a software project, and i
ran "git init" in its source tree, which created the ".git". I added
all files with "git add ." and first-time committed them all using
"git commit -a -m "Imported project files". I also did couple three
commits after that and well, everything works.

What I am wondering about is, what is gits identity for a repository?
I don't share or publish the source directory anywhere, and just for
testing I removed everything but the ".git" directory and tried "git
checkout" and "git checkout master". To my surprise, the files in
repository did NOT reappear, contrary to what I thought. Doesn't
checkout update/recreate the project file tree according to the
"trunk" snapshot?

Now, I did all this just out of curiosity, but to my understanding
everything that is needed for working with the project is stored in
".git", right? Even if all project files mysteriously disappear, "git
checkout" should bring the copy of master branch back, no? If not,
what is the way to tell git I want full copy of a snapshot?

```

## Junio C Hamano, 2009-09-04 20:04

Subject: Re: .git and retrieving full source tree for own project(s)
Message-ID: <7viqfyfpdc.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7viqfyfpdc.fsf%40alter.siamese.dyndns.org
In-Reply-To: <981b72360909041252i29551a5chb8b3a2a5c6444ee3@mail.gmail.com>

```
"armencho@gmail.com" <armencho@gmail.com> writes:

> What I am wondering about is, what is gits identity for a repository?
> I don't share or publish the source directory anywhere, and just for
> testing I removed everything but the ".git" directory and tried "git
> checkout" and "git checkout master".

"git checkout" is a short-hand for "git checkout HEAD" which is to request
"switch to the branch denoted by HEAD, i.e. the current branch, while
keeping my local changes to the work tree and the index".

"git checkout master" is a request to "switch to the master branch, while
keeping my local changes to the work tree and the index".

In this case, your "delete everything" is your local change, and git did
its best to preserve it while switching branches.

If you want to "copy this and that files and directories out of the
commit at the tip of the current branch and deposit them in my work tree
and index", you would say

    $ git checkout HEAD this that

so a request for checking everything out would be a natural extension of
the above that would be:

    $ git checkout HEAD .

If you want to "copy this and that files and directories out of the index
and deposit them in my work tree", you would say

    $ git checkout this that

```

## armencho@gmail.com, 2009-09-04 20:18

Subject: Re: .git and retrieving full source tree for own project(s)
Message-ID: <981b72360909041318m686beea8x11f3076c74c2ee15@mail.gmail.com>
URL: https://gitlist.dev/e/981b72360909041318m686beea8x11f3076c74c2ee15%40mail.gmail.com
In-Reply-To: <7viqfyfpdc.fsf@alter.siamese.dyndns.org>

```
On Fri, Sep 4, 2009 at 22:04, Junio C Hamano<gitster@pobox.com> wrote:
> In this case, your "delete everything" is your local change, and git did
> its best to preserve it while switching branches.
>
> If you want to "copy this and that files and directories out of the
> commit at the tip of the current branch and deposit them in my work tree
> and index", you would say
>
>    $ git checkout HEAD this that
>
> so a request for checking everything out would be a natural extension of
> the above that would be:
>
>    $ git checkout HEAD .
>
> If you want to "copy this and that files and directories out of the index
> and deposit them in my work tree", you would say
>
>    $ git checkout this that
>
>

This makes sense now. I have tested this and it all functions as you
said. Thanks for your help!

```
