gitgit-subtree

Rebase into a subtree


The situation is that we have two repositories, parent and child. The parent repo has the child repo as a subtree:

parent/
  child/

After some time, the child repository has diverged from its upstream (patches have been made for use of the parent project, which have not been contributed to child's upstream).

What is the right Git command to extract a patch from the child subtree (and only that specific patch) so it can be upstreamed?


Solution

  • To clarify, let's name the following branches:

    We want to create the child-feature branch, which contains all the modifications strictly in the feature branch without anything from main.

    We can do so like this:

    git switch -b child-feature feature
    git rebase -i -s subtree --onto child-main main
    

    Explanation: