# Is it possible to git clone --filter= without any objects?

6 messages from 2018-09-11 to 2018-09-12. Participants: Ciro Santilli, Stefan Beller, Jonathan Tan, Junio C Hamano, Matthew DeVore.
Thread: https://gitlist.dev/t/49314

## Ciro Santilli, 2018-09-11 07:29

Subject: Is it possible to git clone --filter= without any objects?
Message-ID: <CAFXrp_fLwL5=K3B5rWjY+imoqtskT8LG-UH8ec3CPwM0iiSzFg@mail.gmail.com>
URL: https://gitlist.dev/e/CAFXrp_fLwL5%3DK3B5rWjY%2BimoqtskT8LG-UH8ec3CPwM0iiSzFg%40mail.gmail.com

```
At v2.19.0 I was trying to clone a fetch just a single directory:
https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934

I got really close with:

git clone --depth 1 --no-checkout --filter=blob:none \
  "file://$(pwd)/server_repo" local_repo
cd local_repo
git checkout master -- mydir/

The only missing thing is that uneeded tree objects are still being fetched.

If I had a:

git clone --filter=none

for example then that would be done.

Nothing major since those are small, but just looking for the perfect
command :-)

```

## Stefan Beller, 2018-09-11 17:15

Subject: Re: Is it possible to git clone --filter= without any objects?
Message-ID: <CAGZ79kYK7ish4_DaZN2bCfZz7LNAjxogQH1k6T=hFcxxkXzJQw@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kYK7ish4_DaZN2bCfZz7LNAjxogQH1k6T%3DhFcxxkXzJQw%40mail.gmail.com
In-Reply-To: <CAFXrp_fLwL5=K3B5rWjY+imoqtskT8LG-UH8ec3CPwM0iiSzFg@mail.gmail.com>

```
On Tue, Sep 11, 2018 at 12:29 AM Ciro Santilli <ciro.santilli@gmail.com> wrote:
>
> At v2.19.0 I was trying to clone a fetch just a single directory:
> https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
>
> I got really close with:
>
> git clone --depth 1 --no-checkout --filter=blob:none \
>   "file://$(pwd)/server_repo" local_repo
> cd local_repo
> git checkout master -- mydir/
>
> The only missing thing is that uneeded tree objects are still being fetched.
>
> If I had a:
>
> git clone --filter=none
>
> for example then that would be done.
>
> Nothing major since those are small, but just looking for the perfect
> command :-)

You might be pleased to hear about a series floating on the mailing list,
that started at
https://public-inbox.org/git/cover.1533854545.git.matvore@google.com/
and promised to filter trees away, and its latest version can be found at
https://public-inbox.org/git/cover.1536081438.git.matvore@google.com/

Thanks,
Stefan

```

## Jonathan Tan, 2018-09-11 17:19

Subject: Re: Is it possible to git clone --filter= without any objects?
Message-ID: <CAGf8dgKLz14ijnXwV0Y=M48Rij-scA19E_uXk3pBc0T02oE_0Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAGf8dgKLz14ijnXwV0Y%3DM48Rij-scA19E_uXk3pBc0T02oE_0Q%40mail.gmail.com
In-Reply-To: <CAGZ79kYK7ish4_DaZN2bCfZz7LNAjxogQH1k6T=hFcxxkXzJQw@mail.gmail.com>

```
On Tue, Sep 11, 2018 at 10:15 AM, Stefan Beller <sbeller@google.com> wrote:
> You might be pleased to hear about a series floating on the mailing list,
> that started at
> https://public-inbox.org/git/cover.1533854545.git.matvore@google.com/
> and promised to filter trees away, and its latest version can be found at
> https://public-inbox.org/git/cover.1536081438.git.matvore@google.com/

I mentioned this in an email to the original poster in which I forgot
to also CC the mailing list:

By "without any objects" in your email subject, do you mean "without
blob and tree objects"? If yes, there is some code in the
md/filter-trees branch that can do that with a "--filter=tree:0"
option. As far as I know, it is not yet in any released version of
Git, but hopefully will be in the next one (the "What's Cooking" [1]
email mentions that it will be merged to the "next" branch, which is
one of the steps before it is released).

[1] https://public-inbox.org/git/xmqqmusw6gbo.fsf@gitster-ct.c.googlers.com/

```

## Junio C Hamano, 2018-09-11 17:46

Subject: Re: Is it possible to git clone --filter= without any objects?
Message-ID: <xmqqo9d4orji.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqo9d4orji.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <CAGf8dgKLz14ijnXwV0Y=M48Rij-scA19E_uXk3pBc0T02oE_0Q@mail.gmail.com>

```
Jonathan Tan <jonathantanmy@google.com> writes:

> By "without any objects" in your email subject, do you mean "without
> blob and tree objects"? If yes, there is some code in the
> md/filter-trees branch that can do that with a "--filter=tree:0"
> option.

I too was wondering what the "without any objects" thing meant
myself.

What would it take on top of the following sequence to create such
an ultra-lazy clone?

	$ mkdir very-sparse && cd very-sparse
	$ git init
	$ git remote add origin $URL

At this point, the repository does not have any object, but it
already knows whom to talk to to get the objects in the project.
The remote must be configured so that it is willing to feed you any
object you name, but would it be just some "git config" magic after
the above three steps to make it as if it was prepared with "git
clone --filter="?  If so, what does that magic look like?

Thanks.

```

## Ciro Santilli, 2018-09-11 18:29

Subject: Re: Is it possible to git clone --filter= without any objects?
Message-ID: <CAFXrp_emK=k7by5pM5=GpsixJVeeJhT89-Cgq3JYbn5yg14CpQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAFXrp_emK%3Dk7by5pM5%3DGpsixJVeeJhT89-Cgq3JYbn5yg14CpQ%40mail.gmail.com
In-Reply-To: <xmqqo9d4orji.fsf@gitster-ct.c.googlers.com>

```
On Tue, Sep 11, 2018 at 6:47 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Jonathan Tan <jonathantanmy@google.com> writes:
>
> > By "without any objects" in your email subject, do you mean "without
> > blob and tree objects"? If yes, there is some code in the
> > md/filter-trees branch that can do that with a "--filter=tree:0"
> > option.
>
> I too was wondering what the "without any objects" thing meant
> myself.
>

Thanks for all replies, as you correctly deduced, I meant "without
fetching any objects".

The mentioned --filter=tree:0 would basically do what I want it seems,
good to hear!. I wonder why not call it tree:none though to match
blob:none.

> What would it take on top of the following sequence to create such
> an ultra-lazy clone?
>
>         $ mkdir very-sparse && cd very-sparse
>         $ git init
>         $ git remote add origin $URL
>

Yes, this would be a good CLI API since the since the clone
--no-checkout --filter --filter gets a bit long.

Or maybe:

git clone --lazy URL repo_local
cd repo_local
git checkout commit -- path/within/repo

Or maybe even:

git clene --lazy URL repo_local COMMITISH path/within/repo

to do both in one go.

People are also interested in commit-less directory / file "clones"
BTW: https://stackoverflow.com/questions/2466735/how-to-checkout-only-one-file-from-git-repository-sparse-checkout

> At this point, the repository does not have any object, but it
> already knows whom to talk to to get the objects in the project.
> The remote must be configured so that it is willing to feed you any
> object you name, but would it be just some "git config" magic after
> the above three steps to make it as if it was prepared with "git
> clone --filter="?  If so, what does that magic look like?
>
> Thanks.

```

## Matthew DeVore, 2018-09-12 01:12

Subject: Re: Is it possible to git clone --filter= without any objects?
Message-ID: <CAMfpvhKYN3E+AJdwFM3k9e4awg5sW8dnVnmROA4W10mQMxWB9A@mail.gmail.com>
URL: https://gitlist.dev/e/CAMfpvhKYN3E%2BAJdwFM3k9e4awg5sW8dnVnmROA4W10mQMxWB9A%40mail.gmail.com
In-Reply-To: <CAFXrp_emK=k7by5pM5=GpsixJVeeJhT89-Cgq3JYbn5yg14CpQ@mail.gmail.com>

```
On Tue, Sep 11, 2018 at 11:30 AM Ciro Santilli <ciro.santilli@gmail.com> wrote:
> The mentioned --filter=tree:0 would basically do what I want it seems,
> good to hear!. I wonder why not call it tree:none though to match
> blob:none.
There are some plans of making tree: accept positive integers in order
to filter out files greater than that depth. e.g. tree:1 would fetch
all blobs and tree objects directly contained by the tree. tree:2
would fetch every object tree:1 does plus anything referred to
directly by those objects.

```
