# Question: git clone --no-checkout behavior

3 messages from 2012-07-12 to 2012-07-12. Participants: Bryan Turner, Junio C Hamano.
Thread: https://gitlist.dev/t/31007

## Bryan Turner, 2012-07-12 12:51

Subject: Question: git clone --no-checkout behavior
Message-ID: <CAGyf7-EZOSiATo3yF5x+FT6_QAkMTJ+AmrE27kwmxLkLXdaJKg@mail.gmail.com>
URL: https://gitlist.dev/e/CAGyf7-EZOSiATo3yF5x%2BFT6_QAkMTJ%2BAmrE27kwmxLkLXdaJKg%40mail.gmail.com

```
I've witnessed the following behavior in both git 1.7.6 and 1.7.10.4.

Assume I have a bare clone, some-repo.git. If I run:
- git clone --shared --no-checkout /path/to/some-repo.git shared-repo
- cd shared-repo
- git status

I see that every file in the repository is _staged_ for deletion. I'm
not surprised every file shows deleted; I'm surprised that the
deletion starts out already staged. A git reset unstages all of the
deletions and I'm good to go. I'm just wondering why they're all
staged in the first place; it seems counter-intuitive.

Can anyone shed some light on this?
Bryan Turner

```

## Junio C Hamano, 2012-07-12 17:40

Subject: Re: Question: git clone --no-checkout behavior
Message-ID: <7vliioc1yn.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vliioc1yn.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAGyf7-EZOSiATo3yF5x+FT6_QAkMTJ+AmrE27kwmxLkLXdaJKg@mail.gmail.com>

```
Bryan Turner <bturner@atlassian.com> writes:

> I've witnessed the following behavior in both git 1.7.6 and 1.7.10.4.
>
> Assume I have a bare clone, some-repo.git. If I run:
> - git clone --shared --no-checkout /path/to/some-repo.git shared-repo
> - cd shared-repo
> - git status

I do not recall we *designed* it in such a way that you would commit
an empty tree if you run "git commit" immediately after making such
a clone.  But I do not think it is a bug, either.

I think the most likely reason nobody even noticed this is because
the expected use scenario for --no-checkout is when user does not
know (and does not care to find out) what branch is checked out (if
nonbare) or marked as the primary (if bare) in the repository she is
cloning from, and will checkout the branch she wants to work on
immediately after cloning, i.e.

	git clone -n $over_there here
        cd here
	# she knows she wants to fork from 'nitfol'
        git checkout -t -b frotz origin/nitfol

Not having anything in the $GIT_DIR/index (which is why you see
"everything is removed from the index, you will commit an empty
tree" in the status output) does not matter in this scenario,
because the first command she invokes will be "git checkout".

If you populated $GIT_DIR/index from the tree of HEAD, you would see
everything is deleted in the working tree.  You can simulate it by
doing this:

	git clone -n $over_there here
        cd here
	git read-tree HEAD
	git status

But it would not help people who want to check another branch out
immediately after cloning with -n, which is the whole point of the
option, so...

```

## Junio C Hamano, 2012-07-12 22:02

Subject: Re: Question: git clone --no-checkout behavior
Message-ID: <7vbojkabad.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbojkabad.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAGyf7-Fkn9bjJ9EZEFNsba8U-RUzrB3TzmB-YbcvwUFRbHXG+Q@mail.gmail.com>

```
Bryan Turner <bturner@atlassian.com> writes:

>> If you populated $GIT_DIR/index from the tree of HEAD, you would see
>> everything is deleted in the working tree.  You can simulate it by
>> doing this:
>>
>>         git clone -n $over_there here
>>         cd here
>>         git read-tree HEAD
>>         git status
>>
>> But it would not help people who want to check another branch out
>> immediately after cloning with -n, which is the whole point of the
>> option, so...
>
> Is the reset call in my example in essence performing that same read-tree,
> when it unstages the changes?

"git reset" (without any other parameters) reads the HEAD tree into
the index without touching the working tree, so I think it is
probably equivalent.

```
