# Creating sparse checkout in a new linked git worktree

3 messages from 2018-01-24 to 2018-01-28. Participants: Jessie Hernandez, Eric Sunshine, Duy Nguyen.
Thread: https://gitlist.dev/t/47682

## Jessie Hernandez, 2018-01-24 16:11

Subject: Creating sparse checkout in a new linked git worktree
Message-ID: <54fd6a226955dc427bb25d5be37b4b0a.squirrel@mail.jessiehernandez.com>
URL: https://gitlist.dev/e/54fd6a226955dc427bb25d5be37b4b0a.squirrel%40mail.jessiehernandez.com

```
Hi All,

I am trying to get a sparse checkout in a linked worktree but cannot get
it working. I have tried the following

* git worktree add /some/new/path/new-branch --no-checkout
* git config core.sparseCheckout true
* <add the directory I would like to checkout out to
$GIT_DIR/info/sparse-checkout>
* cd  /some/new/path/new-branch
* git read-tree -mu sparse-checkout

But I still end up with a fully populated worktree.

Is there something I am missing or doing wrong?

thank you for any response.

jessie



```

## Eric Sunshine, 2018-01-28 07:25

Subject: Re: Creating sparse checkout in a new linked git worktree
Message-ID: <CAPig+cSP0UiEBXSCi7Ua099eOdpMk8R=JtAjPuUavRF4z0R0Vg@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcSP0UiEBXSCi7Ua099eOdpMk8R%3DJtAjPuUavRF4z0R0Vg%40mail.gmail.com
In-Reply-To: <54fd6a226955dc427bb25d5be37b4b0a.squirrel@mail.jessiehernandez.com>

```
On Wed, Jan 24, 2018 at 11:11 AM, Jessie Hernandez
<git@jessiehernandez.com> wrote:
> I am trying to get a sparse checkout in a linked worktree but cannot get
> it working. I have tried the following
>
> * git worktree add /some/new/path/new-branch --no-checkout
> * git config core.sparseCheckout true
> * <add the directory I would like to checkout out to
> $GIT_DIR/info/sparse-checkout>
> * cd  /some/new/path/new-branch
> * git read-tree -mu sparse-checkout
>
> But I still end up with a fully populated worktree.
> Is there something I am missing or doing wrong?

The sparse-checkout file is specific to each worktree, which allows
you to control "sparsity" on a worktree by worktree basis. Therefore,
you should create $GIT_DIR/worktrees/<id>/info/sparse-checkout instead
(where <id> is "new-branch" in your example).

```

## Duy Nguyen, 2018-01-28 09:40

Subject: Re: Creating sparse checkout in a new linked git worktree
Message-ID: <CACsJy8D03LkoT38Xrz0xDUk=Uf=9O0XKrLG0vZMtBxowo9ibNA@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8D03LkoT38Xrz0xDUk%3DUf%3D9O0XKrLG0vZMtBxowo9ibNA%40mail.gmail.com
In-Reply-To: <CAPig+cSP0UiEBXSCi7Ua099eOdpMk8R=JtAjPuUavRF4z0R0Vg@mail.gmail.com>

```
On Sun, Jan 28, 2018 at 2:25 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Wed, Jan 24, 2018 at 11:11 AM, Jessie Hernandez
> <git@jessiehernandez.com> wrote:
>> I am trying to get a sparse checkout in a linked worktree but cannot get
>> it working. I have tried the following
>>
>> * git worktree add /some/new/path/new-branch --no-checkout
>> * git config core.sparseCheckout true
>> * <add the directory I would like to checkout out to
>> $GIT_DIR/info/sparse-checkout>
>> * cd  /some/new/path/new-branch
>> * git read-tree -mu sparse-checkout
>>
>> But I still end up with a fully populated worktree.
>> Is there something I am missing or doing wrong?
>
> The sparse-checkout file is specific to each worktree, which allows
> you to control "sparsity" on a worktree by worktree basis. Therefore,
> you should create $GIT_DIR/worktrees/<id>/info/sparse-checkout instead
> (where <id> is "new-branch" in your example).

Nit. Do

    $EDITOR `git rev-parse --git-path info/sparse-checkout`

if you're already in the right worktree so you don't have to find out
about <id> or the full path.

I wanted to add "git checkout --edit-sparse" for some time. Using it
in multiple worktrees may be a good push for me to eventually do it.
-- 
Duy

```
