# Merging only a subdirectory from one branch to the other

3 messages from 2012-02-07 to 2012-02-10. Participants: Howard Miller, Taylor Hedberg, Neal Kreitzinger.
Thread: https://gitlist.dev/t/29567

## Howard Miller, 2012-02-07 09:38

Subject: Merging only a subdirectory from one branch to the other
Message-ID: <CAHVO_90MQamw7oB8ry5YBEWSnRnxDZvQ4ApVuuv4AYR6VRuXSw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHVO_90MQamw7oB8ry5YBEWSnRnxDZvQ4ApVuuv4AYR6VRuXSw%40mail.gmail.com

```
Hi,

I've been Googling for this one and am, mostly, more confused than
when I started so if you could humor me for a moment.

I have a branch with a particular subdirectory tree. The tree has a
lot of history. However, all the history for that subdirectory is
exclusive to it (no commits changed anything outside it). I now need
to merge that subdirectory into a completely different branch without
loosing any history. I think git-read-tree might have something to do
with it but I don't understand the help file at all. Any help
appreciated.

Cheers....

```

## Taylor Hedberg, 2012-02-07 15:24

Subject: Re: Merging only a subdirectory from one branch to the other
Message-ID: <20120207152457.GB2662@foodlogiq3-xp-d620>
URL: https://gitlist.dev/e/20120207152457.GB2662%40foodlogiq3-xp-d620
In-Reply-To: <CAHVO_90MQamw7oB8ry5YBEWSnRnxDZvQ4ApVuuv4AYR6VRuXSw@mail.gmail.com>

```
Howard Miller, Tue 2012-02-07 @ 09:38:22+0000:
> I have a branch with a particular subdirectory tree. The tree has a
> lot of history. However, all the history for that subdirectory is
> exclusive to it (no commits changed anything outside it). I now need
> to merge that subdirectory into a completely different branch without
> loosing any history. I think git-read-tree might have something to do
> with it but I don't understand the help file at all. Any help
> appreciated.

You might find git-subtree [1] useful for this. The `git subtree split`
sub-command in particular enables you to factor out the history of a
particular subdirectory in your repo into a separate branch, which you
could then merge into some other branch as desired.


[1] https://github.com/apenwarr/git-subtree

```

## Neal Kreitzinger, 2012-02-10 00:51

Subject: Re: Merging only a subdirectory from one branch to the other
Message-ID: <4F346A21.2080008@gmail.com>
URL: https://gitlist.dev/e/4F346A21.2080008%40gmail.com
In-Reply-To: <CAHVO_90MQamw7oB8ry5YBEWSnRnxDZvQ4ApVuuv4AYR6VRuXSw@mail.gmail.com>

```
On 2/7/2012 3:38 AM, Howard Miller wrote:

> I have a branch with a particular subdirectory tree. The tree has a
> lot of history. However, all the history for that subdirectory is
> exclusive to it (no commits changed anything outside it). I now need
> to merge that subdirectory into a completely different branch without
> loosing any history. I think git-read-tree might have something to do
> with it but I don't understand the help file at all. Any help
> appreciated.
>
Does the 'subtree merge' described in this link do what you want: 
http://progit.org/book/ch6-7.html
(I can't say I've actually tried it myself, yet.)

v/r,
neal

```
