Git submodule in a project ¶
(1) Add submodule to project
git submodule add ssh://.../djangolib src/djangolib Cloning into src/djangolib... git submodule update --init Submodule 'src/djangolib' (ssh://.../djangolib) registered for path 'src/djangolib'
Spostarsi in src/djangolib e controllare che sia nel branch "master", altrimenti eseguire git checkout master
(2) modifiche a buildout.cfg
develop = src/djangolib [versions] silverbullet.djangolib = 3.0.12
Questa versione va' poi riportata in setup.py
(3) Per rimuovere il submodule
git rm --cached src/djangolib
Per la rimozione di un submodule, vedere anche:
Completely remove a submodule no more needed
git submodule deinit THE_SUBMODULE Cleared directory 'THE_SUBMODULE' Submodule 'THE_SUBMODULE' (https://github.com/morlandi/THE_SUBMODULE.git) unregistered for path 'THE_SUBMODULE' git rm THE_SUBMODULE rm 'THE_SUBMODULE' rm -fr .git/modules/THE_SUBMODULE
Updating a fork with modified submodules
You can easily add you own repos to each submodule as you modify them. You need to for the repo in github so you have your own fork. cd to the module and then rename the origin which is pointing to original repo to be upstream. the you can add your repo as origin. (note the example below is for mavlink module, but you would do the same for each module dependency you wanted to work on)
cd ardupilot/modules/mavlink git remote rename origin upstream git remote add origin https://github.com/<my_username>/ardupilot.git git checkout master (or git checkout -b my_modfied_branch to create you modified branch ready for a PR)
then to push you use the git push origin <branch_name> to save in your own repo in github
Do the same of a clone on another machine, you can then go to the module dir and pull down, and push up your changes to your local repo
Swap git submodule with own fork
The submodules are stored in .gitmodules:
cat .gitmodules [submodule "ext/google-maps"] path = ext/google-maps url = git://git.naquadah.org/google-maps.git
If you edit the url with a text editor, you need to run the following:
$ git submodule sync
This updates .git/config which contains a copy of this submodule list (you could also just edit the relevant [submodule] section of .git/config manually)
References: https://stackoverflow.com/questions/11637175/swap-git-submodule-with-own-fork#11637270
What is a good workflow for submodule forks
See:
https://stackoverflow.com/questions/7174347/what-is-a-good-workflow-for-submodule-forks#7174827
Also note that:
Another, simple solution is to tell git to ignore .gitmodules and to remove them from tracking.
As said above, .gitmodules are used only for initializing submodules, so it's needed only once, upon checking out the submodules.