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