Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to include part of another git repository using git subtree and merge updates in both directions
    text
    copied!<p>I have two git repositories show below. The first is structured like a typical python project.</p> <pre><code>foo_repo/ .git/ setup.py foo/ __init__.py some_code.py tests/ bar/ .git/ </code></pre> <p>I would like to include the <code>foo_repo/foo/</code> directory in <code>bar/</code> as a subtree and I want to be able to merge updates to <code>foo_repo/foo/some_code.py</code> both from the foo_repo repository to bar and vice versa.</p> <p>The initial setup isn't too bad. From the <code>foo/</code> directory I use:</p> <pre><code>git subtree --prefix=foo/ split -b export </code></pre> <p>Then I have a new branch in foo_repo with only the contents of the <code>foo_repo/foo/</code> directory. To bring this into bar, I just go to the <code>bar/</code> directory and:</p> <pre><code>git subtree --prefix=foo/ add ../foo_repo/.git export </code></pre> <p>Now that I'm all set up, I'd like to do some code development and keep <code>foo/</code> up to date in both repos. Pushing from bar I think I have figured out. From <code>bar/</code> directory:</p> <pre><code>touch foo/more_code.py git add foo/more_code.py git commit -m "more code" git subtree --prefix=foo/ push ../foo_repo/.git export </code></pre> <p>Then from the <code>foo_repo/</code> directory:</p> <pre><code>git checkout master git subtree --prefix=foo/ merge export </code></pre> <p>Merging the other way is where I'm stuck. From <code>foo_repo/</code>:</p> <pre><code>git checkout master touch foo/yet_more_code.py git add foo/yet_more_code.py git commit -m "yet more code" ??? </code></pre> <p>Where the <code>???</code> is a command that merges the <code>foo/</code> directory with the <code>export</code> branch. Then from <code>bar/</code>:</p> <pre><code>git subtree --prefix=foo/ pull ../foo_repo/.git export </code></pre> <p>So I'm basically looking for the line that goes in the <code>???</code> spot, or a different workflow that does the same thing. I've tried repeating <code>git subtree --prefix=foo/ split -b export_foo</code> by that doesn't work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload