Search code examples
gitgit-submodulessubtreegit-subtree

Git's subtree merge strategy doesn't pick the right directory


I have a repository that looks something like this:

foo/
    subrepo/
        a_file_in_subrepo
        another.ext
    unrelated_file

subrepo is a repository on github, and I have a remote in my repository, say sub, that tracks it, but none of the files are merged.

What I want is to merge in sub/master at the subrepo folder. I know that a_file_in_subrepo and another.ext are exactly as they are in sub/master but if I run git merge -s subtree sub/master I don't get what I want, and instead get:

foo/
    subrepo/
        a_file_in_subrepo
        another.ext
    unrelated_file
    a_file_in_subrepo
    another.ext

I'm really confused. I know it guesses the directory to merge into automagically, can I override that?


Solution

  • Use the -Xsubtree=<path> option to the recursive merge strategy:

    git merge -s recursive -Xsubtree=subrepo sub/master