What optimisations exist (including even alternatives to git subtree) if you wish to include a subproject in your main project but never contribute changes upstream?
Actual use case: I am embedding Ghost into an existing express.js website, e.g. into lib/Ghost. I will need to make a few hacks to it, the type they would not want contributed upstream anyway. Any normal contributing to the Ghost project would be done via a typical forking on GitHub, instead of from within my other project.
Therefore after the initial embedding of Ghost into my project, the only things happening would be the occasional local source code change, plus sometimes fetching from upstream for updates from their master branch.
In such a scenario, is git subtree still a suitable approach, and if it is then are there either any gotchas or simplifications which would apply, due to this need to never contribute upstream? And would it therefore also be possible to have the main TryGhost/Ghost repository as my subtree upstream, rather than first forking Ghost and then having the fork as the project's upstream?
Subtree sounds like a really good fit to me.
If you're making any local changes at all, I think subtree is a better fit over submodules.
The only downside I can think of is that you have a full copy of the sub-projects in your repository, but unless it's an enormous project that's optional for your super-project who cares about that?
You should not need to make a branch for the subproject, just:
git subtree add --prefix Ghost --squash -m "Adding Ghost." https://github.com/TryGhost/Ghost.git master
You can freely make changes from that point on and completely ignore the fact that it originally came from Ghost depot. You don't even need to add the remote as you can tell from my example above.
If you pull often, you may want to create the remote.
git remote add ghost https://github.com/TryGhost/Ghost.git
git subtree pull --prefix=Ghost --squash -m "Updating Ghost." ghost master
Finally, even if you decide at some later point that you want to contribute back upstream, to a fork or wherever, it's really simple for you to just split out the parts relevant to the sub-project into a branch and then just push the changes from that branch to the fork repository.
git subtree split -p Ghost -b Ghost-contrib-br --rejoin
# this should switch to the branch with only the ghost files
git push <remote-contrib-repo>
Note: I didn't use --squash
because the history will be only what you modified since the add or last --rejoin
--rejoin
is kind of a lame hack which commits back to your super-project so the split command knows the best starting point for the next split. In the future I think this will be managed from a new section the .git/config (I may even make it so myself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With