I finally figured out how to create a subtree repository out of my main repository with Git.
There's one thing left that I'm not really sure of. Assume that "Main" is the repository that holds all of my code and "Shared" is the subfolder that I splitted from "Main".
When I make changes to code in my Main repo and also changes in the "Shared" repo, how do I then proceed?
Can i first do a commit
on the "Main" repo if I made changes to both, the "Main" code and the "Shared" repo?
git commit -am "Made changes to main and shared"
Should I then ALWAYS do a push
first to the "Shared" repo?
git subtree push --prefix=path/to/code --squash shared master
And after that simply push the "Main" repo:
git push
Should I always commit and push like this from now on? Or is this maybe the wrong approach?
Not always, since you could want to keep some subtree modifications only in the context of your Main
repo, in which case a simple commit + push in said Main
repo is enough (you don't have to contribute back to the subtree upstream repo in that case).
That differs from submodule, where any modification in a submodule need to be committed, and then you need to go back to the parent repo and commit again (to record the new SHA1 of that submodule).
In that case (submodule), yes, it is advised to push the submodule first (to its upstream repo), before pushing the parent repo: anyone cloning the parent repo would want to get said SHA1 from the submodule upstream repo (and if you didn't push the submodule... that SHA1 wouldn't be available).
In a subtree, the Main repo includes everything, so pushing the Main repo can be enough.
You push to the upstream repo of the subtree only if you want your modifications to be reflected in that upstream repo.