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.
If you split again foo/
the new commits created for this subtree will be created on top of the old commits already existing in export
, including the merges that are needed for such:
git subtree --prefix=foo/ split
Notice that if using the -b
option the branch should not exist previuosly, so you might need to create a new branch or later force it to change.