Adapted from here. Below is an executive summary for the use case of a university collaborative thesis project.
Say we have the thesis repo and some other, subproject repo (the memory-engine repo in this example).
We want the thesis to be the "main" repository, such that on a new machine, just pulling it is enough to get us started.
We also want to make it easy to make changes to code either to a memory-engine/ code, or to code in the thesis/ or to both, without having to bump versions/commits every time we push to memory-engiine.
We could have used git submodules but it's so much pain (really).
- In
thesisgit remote add memory-engine-origin git@github.com:warreee/memory-engine.git - add the subtree (this will clone the master of the
memory-enginerepo and configre the thesis) repo.git subtree add --prefix=memory-engine/ memory-engine-origin master
We have opened the thesis repo in pycharm, we make a change in the 'memory-engine' folder and want to just want to publish our changes without having to push first to the memory-engine repo and then pulling from thesis.
- e.g. if we are in
thesis/, we can make changes to the memory-enginetouch ./memory-engine/boo - and then push the changes to the
thesisrepogit commit -am "added boo"git push origin master(origin here is the thesis origin)
In GitHub of thesis, the commit would appear. Nothing special, but still useful because we didn't have to bump versions anywhere.
Example - change files in both the thesis and the memory-engine folders:
- make the changes
georgi@georgi-laptop:~/Projects/thesis/memory-engine(master)$ echo "boo :)" >> README.mdgeorgi@georgi-laptop:~/Projects/thesis(master)$ echo "testing" >> README.md - make a commit and push it to the
thesisrepogit commit -am "made a commit to both repos"git push origin master - Push to the
memory-enginerepogeorgi@georgi-laptop:~/Projects/thesis(master)$ git subtree push --prefix memory-engine memory-engine-origin master - If we open the GitHub of
thesis- we will see the commit, with both files changed. If we open the GitHub ofmemory-engine, only the memory-engine/README.md will be in the commit. Voila