Let say I'm owner of two remote projects: MainProject
and AppsProject
.
In local repository I want to have AppsProject
in MainProject
's subdirectory (apps/
).
I've tried to use subtree merge
strategy (ref.: Pro Git Book)
In MainProject
's directory. I've done that:
$ git remote add apps-remote [email protected]:me/apps.git
$ git checkout -b apps-branch apps-remote/master
$ git checkout master
$ git read-tree --prefix=apps/ -u apps-branch
$ git checkout apps-branch
$ git pull
Actually what I want now is to be able commit local apps/
changes to AppsProject
remote repository and anything what is not in apps/
to MainProject
remote repository.
How to do that?
To create a submodule:
$ cd MainProject
$ git submodule add [email protected]:me/apps.git apps
$ git commit -a -m "added a submodule"
$ git push
Now to clone brand new:
$ git clone --recursive [email protected]:me/MainProject.git
Or if you had it cloned somewhere already but before you added the submodule:
$ git submodule update --init
#Or without the --init to update the submodule
Keep in mind that when you make changes to the submodule, you first want to commit the changes in the submodule, and then commit the changes in the main repo so that it picks it up. The submodule is always frozen at the last commit in the main repo.