% Git Submodules - The Good + The Bad % Paul Matthews % March 2012
- Submodules
- Essentials
- Using submodules
- Using distributed submodules
- Alternatives
- Include other git repos
- Anywhere in the tree
- Submodules != svn:externals
- Only entire repos
- Use in conjunction with symlinks (linux)
-
Include other git projects
-
Including OS projects, such as frameworks
-
Create a custom structure for your codebase
-
Deployment?
- Data structure like linked list
- Everything is a reference
- Branches
- Tags
- Commit can be multiple branches / tags
- Branch HEAD is only branch
- Submodules refer to a commit
- Look like a repo inside a repo
- Inside the submodule you can't tell you're in submodule
- Parent : Amazon
- Child : Magento
- Do Nothing from child
- Just Add them
git submodule add <repo> <location>
- 2 stage process
- Need to initialise the submodules
git submodule init
- Then pull the submodules down
git submodule update
- Alternatively use "--recursive" clone
- Submodules don't update themselves
- Good / Bad
- Add the submodule like a file
- Work-flow:
- Work on child
- Commit
- Goto parent
- Add child reference
- Commit
- Work on child
cd ~/amazon/magento
vim index.php
- Commit
commit -am "Updating magento"
- Goto parent
cd ~/amazon
- Add child reference
add ~/amazon/magento
- Commit
commit -m "Getting latest version of magento"
- Submodules don't support multiple remotes
- by default
- Can be used to checkout multiple repos
- Into a specific state
- Useful for distributing many repos to teams
- User can check in an inaccessible commit
- Utility command
git submodule foreach [command]
- e.g:
git submodule foreach git branch
- Children contain feature branches
- So too can the parent
- Ensures correct libraries per feature
- Ensures system state
- Create an init script
- Adds all the remotes
- Beware:
- HEAD commit of submodule must be accessible on default remote
- Subtree Merging
- More useful for frameworks and libraries
- You commit the child code to your parent branch
- Submodules
- Essentials
- Using submodules
- Using distributed submodules
- Alternatives