Playing With Git Submodule
Intructions:
1
2
| $ git submodule add -b BRANCH ssh://REPO_URL/REPO_PATH SUBMODULE_PATH
$ git commit -m "add a submodule at SUBMODULE_PATH"
|
- clone the project with submodule(s)
1
2
3
| $ git clone ssh://REPO_URL/REPO_PATH PROJECT
cd PROJECT
$ git submodule update --init --rebase
|
1
2
| $ git submodule status
$ git submodule foreach git branch -a
|
- checkout all submodule to a branch defined in .gitmodule (which means we specify the branch when we add the submodule with ‘-b BRANCH’)
1
2
3
| $ git submodule foreach -q --recursive 'branch="$(git config -f $toplevel/.gitmodules submodule.$name.branch)"; git checkout $branch'
# OR a short version
$ git submodule foreach git checkout master
|
- pull the latest master for all of the submodule
1
| $ git submodule -q foreach git pull -q origin master
|
1
2
3
4
5
| # Make your changes in submoduleA
$ cd submoduleA
$ git add .
$ git commit -m "Updated the submoduleA"
$ git push origin BRANCH
|
1
2
3
| $ cd PROJECT
$ git pull
$ git submodule update --rebase
|
- manually update the project to track submodule (Gerrit submodule description commit the track automatically)
1
2
3
4
| $ cd PROJECT
$ git add submoduleA
$ git commit -m "Updated submodule a."
$ git push origin BRANCH_NAME
|
- deinit, and remove a submodule
1
2
3
| $ git submodule deinit SUBMODULE_PATH
$ git rm SUBMODULE_PATH
$ git commit -m "remove the submodule at SUBMODULE_PATH"
|
References:
- http://git-scm.com/docs/git-submodule
- http://git-scm.com/docs/git-rm.html
- http://stackoverflow.com/questions/8642668/how-to-make-submodule-with-detached-head-to-be-attached-to-actual-head
- http://www.vogella.com/tutorials/Git/article.html#submodules
Written with StackEdit.