# Splitting up a repository

6 messages from 2010-12-04 to 2010-12-04. Participants: Evan Driscoll, Jeff King, Nguyen Thai Ngoc Duy.
Thread: https://gitlist.dev/t/25948

## Evan Driscoll, 2010-12-04 05:27

Subject: Splitting up a repository
Message-ID: <4CF9D15D.7090001@cs.wisc.edu>
URL: https://gitlist.dev/e/4CF9D15D.7090001%40cs.wisc.edu

```
Say I have a repo where there are directories repo/foo, repo/bar,
repo/baz. 'foo', 'bar', and 'baz' are loosely related -- closely enough
that I put them together initially, but loosely enough that I now wish I
could check out just 'repo/foo'. Since Git doesn't support partial
checkouts (a bit annoying!), I now have to split this repository into
separate ones. I'd of course like to keep history.

Is there a better way than making several (recursive) copies of the
repository, deleting all but one directory in each copy, then moving the
contents of that directory up a level? (And perhaps setting up a Git
superproject at the original location. I do know about that.)

I've probably spent more time typing up this email than it would take to
do, but I'm curious if there's some git magic or something that would be
better for some reason. :-)

Evan


```

## Jeff King, 2010-12-04 05:33

Subject: Re: Splitting up a repository
Message-ID: <20101204053304.GA7311@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20101204053304.GA7311%40sigill.intra.peff.net
In-Reply-To: <4CF9D15D.7090001@cs.wisc.edu>

```
On Fri, Dec 03, 2010 at 11:27:57PM -0600, Evan Driscoll wrote:

> Say I have a repo where there are directories repo/foo, repo/bar,
> repo/baz. 'foo', 'bar', and 'baz' are loosely related -- closely enough
> that I put them together initially, but loosely enough that I now wish I
> could check out just 'repo/foo'. Since Git doesn't support partial
> checkouts (a bit annoying!), I now have to split this repository into
> separate ones. I'd of course like to keep history.
> 
> Is there a better way than making several (recursive) copies of the
> repository, deleting all but one directory in each copy, then moving the
> contents of that directory up a level? (And perhaps setting up a Git
> superproject at the original location. I do know about that.)

Rewrite the history of each directory with git-filter-branch. It even
has a "--subdirectory-filter" option that will do exactly what you want.

-Peff

```

## Evan Driscoll, 2010-12-04 06:19

Subject: Re: Splitting up a repository
Message-ID: <4CF9DD5E.7020400@cs.wisc.edu>
URL: https://gitlist.dev/e/4CF9DD5E.7020400%40cs.wisc.edu
In-Reply-To: <20101204053304.GA7311@sigill.intra.peff.net>

```
On 12/3/2010 23:33, Jeff King wrote:
>> Is there a better way than making several (recursive) copies of the
>> repository, deleting all but one directory in each copy, then moving the
>> contents of that directory up a level? (And perhaps setting up a Git
>> superproject at the original location. I do know about that.)
> 
> Rewrite the history of each directory with git-filter-branch. It even
> has a "--subdirectory-filter" option that will do exactly what you want.

Great, thanks. I had to mess around with a submodule that was inside one
of the subdirectories that didn't make it through the history rewrite,
and I could see that have getting slightly hairy, but at least in my
case it was pretty simple. Other than that, worked like a charm.

Evan


```

## Nguyen Thai Ngoc Duy, 2010-12-04 07:09

Subject: Re: Splitting up a repository
Message-ID: <AANLkTikqnnOLN=asPUKK0zYxYK9VWXcZPBPtwMZ3z-cr@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikqnnOLN%3DasPUKK0zYxYK9VWXcZPBPtwMZ3z-cr%40mail.gmail.com
In-Reply-To: <4CF9D15D.7090001@cs.wisc.edu>

```
On Sat, Dec 4, 2010 at 12:27 PM, Evan Driscoll <driscoll@cs.wisc.edu> wrote:
> Say I have a repo where there are directories repo/foo, repo/bar,
> repo/baz. 'foo', 'bar', and 'baz' are loosely related -- closely enough
> that I put them together initially, but loosely enough that I now wish I
> could check out just 'repo/foo'. Since Git doesn't support partial
> checkouts (a bit annoying!),

Um.. it does support partial checkouts (check out man page of
git-read-tree, sparse checkout section). But you must do a full clone
(i.e. your repository will have bar and baz, even if you only checkout
foo).
-- 
Duy

```

## Evan Driscoll, 2010-12-04 07:14

Subject: Re: Splitting up a repository
Message-ID: <4CF9EA60.7040402@cs.wisc.edu>
URL: https://gitlist.dev/e/4CF9EA60.7040402%40cs.wisc.edu
In-Reply-To: <AANLkTikqnnOLN=asPUKK0zYxYK9VWXcZPBPtwMZ3z-cr@mail.gmail.com>

```
On 12/4/2010 1:09, Nguyen Thai Ngoc Duy wrote:
> On Sat, Dec 4, 2010 at 12:27 PM, Evan Driscoll <driscoll@cs.wisc.edu> wrote:
>> Say I have a repo where there are directories repo/foo, repo/bar,
>> repo/baz. 'foo', 'bar', and 'baz' are loosely related -- closely enough
>> that I put them together initially, but loosely enough that I now wish I
>> could check out just 'repo/foo'. Since Git doesn't support partial
>> checkouts (a bit annoying!),
> 
> Um.. it does support partial checkouts (check out man page of
> git-read-tree, sparse checkout section). But you must do a full clone
> (i.e. your repository will have bar and baz, even if you only checkout
> foo).

That's sort of spiffy, and I did not know about that. So again, thanks.

That said, I did a bit of reading around, and I'm not sure it does what
I need.
http://stackoverflow.com/questions/2336580/sparse-checkout-in-git-1-7-0
is basically what I want, and the answers seem to indicate it isn't
possible. (In other words, in my example, when I want a checkout of
repo/foo, the .git directory needs to be a sibling of foo's contents,
not a sibling of foo.)

Evan


```

## Nguyen Thai Ngoc Duy, 2010-12-04 07:41

Subject: Re: Splitting up a repository
Message-ID: <AANLkTinLFZTFgov9RtNTFS36BV0xyTm6=kpDE3VZFcEG@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinLFZTFgov9RtNTFS36BV0xyTm6%3DkpDE3VZFcEG%40mail.gmail.com
In-Reply-To: <4CF9EA60.7040402@cs.wisc.edu>

```
On Sat, Dec 4, 2010 at 2:14 PM, Evan Driscoll <driscoll@cs.wisc.edu> wrote:
> On 12/4/2010 1:09, Nguyen Thai Ngoc Duy wrote:
>> On Sat, Dec 4, 2010 at 12:27 PM, Evan Driscoll <driscoll@cs.wisc.edu> wrote:
>>> Say I have a repo where there are directories repo/foo, repo/bar,
>>> repo/baz. 'foo', 'bar', and 'baz' are loosely related -- closely enough
>>> that I put them together initially, but loosely enough that I now wish I
>>> could check out just 'repo/foo'. Since Git doesn't support partial
>>> checkouts (a bit annoying!),
>>
>> Um.. it does support partial checkouts (check out man page of
>> git-read-tree, sparse checkout section). But you must do a full clone
>> (i.e. your repository will have bar and baz, even if you only checkout
>> foo).
>
> That's sort of spiffy, and I did not know about that. So again, thanks.
>
> That said, I did a bit of reading around, and I'm not sure it does what
> I need.
> http://stackoverflow.com/questions/2336580/sparse-checkout-in-git-1-7-0
> is basically what I want, and the answers seem to indicate it isn't
> possible. (In other words, in my example, when I want a checkout of
> repo/foo, the .git directory needs to be a sibling of foo's contents,
> not a sibling of foo.)

If you want different layout too, then no it does not do that.
Splitting repo is probably best.
-- 
Duy

```
