SlideShare a Scribd company logo
1 of 13
Download to read offline
git submodule

         Olaf Alders
 olaf@wundercounter.com
twitter.com/wundercounter
   Toronto Perl Mongers
       Sept 29, 2011
What does it do?

Git's submodule support allows a repository to contain, as a subdirectory, a checkout of an external project.
Submodules maintain their own identity; the submodule support just stores the submodule repository location and
commit ID, so other developers who clone the containing project ("superproject") can easily clone all the
submodules at the same revision. Partial checkouts of the superproject are possible: you can tell Git to clone none,
some or all of the submodules.

source: "Git Community Book"
http://book.git-scm.com/5_submodules.html
An Example:

mkdir shiny_app
cd shiny_app/
git init
mkdir inc
mkdir -p root/static/js
mkdir -p root/static/css
echo "shiny app" > README
git add .
git commit -a -m "initial commit"
Add a submodule

git submodule add https://github.com/twitter/bootstrap.git inc/bootstrap

git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: .gitmodules
# new file: inc/bootstrap

cat .gitmodules
[submodule "inc/bootstrap"]
path = inc/bootstrap
url = https://github.com/twitter/bootstrap.git

git commit -a -m "adds bootstrap as submodule"
Link it up!

mkdir root/static/css
mkdir root/static/js
ln -s inc/bootstrap/bootstrap.min.css root/static/css/
ln -s inc/bootstrap/js root/static/js/bootstrap

git commit root -m "adds bootstrap symlinks"
Now what?

  ● Work as you normally would
  ● Later, when you want to update bootstrap to the latest version

cd inc/bootstrap
git pull origin master
cd ../..
git commit inc/bootstrap -m "updates bootstrap"
Cloning repos with submodules

When someone else clones your repo, they need to update and init:

$ cd ..
git clone shiny_app bootstrapper
Cloning into bootstrapper...
done.

$ cd bootstrapper/
$ ls
README inc root
olaf-alderss-macbook-pro:bootstrapper olaf

$ ls inc/bootstrap/

# no output above -- the inc/bootstrap folder is empty
Remember to init and update

We've got the repo, but the submodule is empty. Two commands will fix that.

$ git submodule init
Submodule 'inc/bootstrap' (https://github.com/twitter/bootstrap.git) registered
for path 'inc/bootstrap'

$ git submodule update
Cloning into inc/bootstrap...
remote: Counting objects: 3845, done.
remote: Compressing objects: 100% (1430/1430), done.
remote: Total 3845 (delta 2474), reused 3663 (delta 2329)
Receiving objects: 100% (3845/3845), 1.04 MiB | 388 KiB/s, done.
Resolving deltas: 100% (2474/2474), done.
Submodule path 'inc/bootstrap': checked out
'28c770bf679e131cc030c3bc4a1981450f831908'
Is your HEAD detached?

By default, the submodule in the cloned repo will not be on a
branch:

cd inc/bootstrap/
git branch
* (no branch)
  master

Try to remember to work on a branch before committing:

$ git checkout master
Oops!

If you commit while not on a branch, you'll get the following "detached HEAD"
message:

$ git commit README.md -m "random change"
[detached HEAD b92b798] random change
 1 files changed, 3 insertions(+), 0 deletions(-)

This is easy to recover from. Just check out a branch and merge the commit:

$ git checkout master
$ git merge b92b798
git pull != git submodule update

Team members should remember to change their workflow to:

git pull origin master
git submodule update

Remember, a pull does not fetch submodule updates. To stay
totally in sync, team members will want to update submodules
as they pull.
Caveat

Merge conflicts
If two team members commit the same submodule with
differing HEADs, you will get a merge conflict. You will need to
resolve this manually.
What do you gain from submodules?

 ● You can build and test against bleeding edge checkouts
 ● You don't have to add someone else's code to your repo
 ● Team members can build against exactly the checkout you've built and
   tested against and vice versa
 ● Updating your submodules is trivial

More Related Content

What's hot

What's hot (20)

Github
GithubGithub
Github
 
Découvrir et utiliser Git : le logiciel de gestion de versions décentralisé
Découvrir et utiliser Git : le logiciel de gestion de versions décentraliséDécouvrir et utiliser Git : le logiciel de gestion de versions décentralisé
Découvrir et utiliser Git : le logiciel de gestion de versions décentralisé
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Version control system and Git
Version control system and GitVersion control system and Git
Version control system and Git
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Les bases de git
Les bases de gitLes bases de git
Les bases de git
 
CI-CD WITH GITLAB WORKFLOW
CI-CD WITH GITLAB WORKFLOWCI-CD WITH GITLAB WORKFLOW
CI-CD WITH GITLAB WORKFLOW
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
git and github
git and githubgit and github
git and github
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CI
 

Viewers also liked

Mobile App Test Strategy
Mobile App Test StrategyMobile App Test Strategy
Mobile App Test Strategy
kraqa
 
Grafico diario del dax perfomance index para el 10 04-2013
Grafico diario del dax perfomance index para el 10 04-2013Grafico diario del dax perfomance index para el 10 04-2013
Grafico diario del dax perfomance index para el 10 04-2013
Experiencia Trading
 
Grafico diario del dax perfomance index para el 12 02-2013
Grafico diario del dax perfomance index para el 12 02-2013Grafico diario del dax perfomance index para el 12 02-2013
Grafico diario del dax perfomance index para el 12 02-2013
Experiencia Trading
 
Chan presentation final
Chan presentation finalChan presentation final
Chan presentation final
Daniel Chan
 
Wang - A practical model for curricular integration of information literacy i...
Wang - A practical model for curricular integration of information literacy i...Wang - A practical model for curricular integration of information literacy i...
Wang - A practical model for curricular integration of information literacy i...
IL Group (CILIP Information Literacy Group)
 

Viewers also liked (19)

Recycling
RecyclingRecycling
Recycling
 
Git Submodules
Git SubmodulesGit Submodules
Git Submodules
 
Advanced Git: Functionality and Features
Advanced Git: Functionality and FeaturesAdvanced Git: Functionality and Features
Advanced Git: Functionality and Features
 
10th php indonesia surabaya meetup
10th php indonesia surabaya meetup10th php indonesia surabaya meetup
10th php indonesia surabaya meetup
 
Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositories
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAdvanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
 
Mobile App Test Strategy
Mobile App Test StrategyMobile App Test Strategy
Mobile App Test Strategy
 
Fetch apiについて
Fetch apiについてFetch apiについて
Fetch apiについて
 
Grafico diario del dax perfomance index para el 10 04-2013
Grafico diario del dax perfomance index para el 10 04-2013Grafico diario del dax perfomance index para el 10 04-2013
Grafico diario del dax perfomance index para el 10 04-2013
 
Grafico diario del dax perfomance index para el 12 02-2013
Grafico diario del dax perfomance index para el 12 02-2013Grafico diario del dax perfomance index para el 12 02-2013
Grafico diario del dax perfomance index para el 12 02-2013
 
Prueba de portada
Prueba de portadaPrueba de portada
Prueba de portada
 
Universidad nacional de chimborazo
Universidad nacional de chimborazoUniversidad nacional de chimborazo
Universidad nacional de chimborazo
 
Quiz families march 2105 quiz
Quiz families march 2105 quizQuiz families march 2105 quiz
Quiz families march 2105 quiz
 
How to build brands and influence people
How to build brands and influence peopleHow to build brands and influence people
How to build brands and influence people
 
Chan presentation final
Chan presentation finalChan presentation final
Chan presentation final
 
コイルのスパイスモデル
コイルのスパイスモデルコイルのスパイスモデル
コイルのスパイスモデル
 
Wang - A practical model for curricular integration of information literacy i...
Wang - A practical model for curricular integration of information literacy i...Wang - A practical model for curricular integration of information literacy i...
Wang - A practical model for curricular integration of information literacy i...
 
Figuras literarias
Figuras literariasFiguras literarias
Figuras literarias
 
"Using Blockchain Technology to Maintain OERs and IPs" by Sherry Jones (April...
"Using Blockchain Technology to Maintain OERs and IPs" by Sherry Jones (April..."Using Blockchain Technology to Maintain OERs and IPs" by Sherry Jones (April...
"Using Blockchain Technology to Maintain OERs and IPs" by Sherry Jones (April...
 

Similar to Git submodule

Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductor
timyates
 

Similar to Git submodule (20)

Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
 
Transformative Git Practices
Transformative Git PracticesTransformative Git Practices
Transformative Git Practices
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductor
 
Switching to Git
Switching to GitSwitching to Git
Switching to Git
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for Git
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
 
Getting Into Git
Getting Into GitGetting Into Git
Getting Into Git
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
 
Jedi Mind Tricks in Git
Jedi Mind Tricks in GitJedi Mind Tricks in Git
Jedi Mind Tricks in Git
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Git single branch
Git single branchGit single branch
Git single branch
 
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -EssentialsJAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
GitLab on OpenShift
GitLab on OpenShiftGitLab on OpenShift
GitLab on OpenShift
 
Getting Started with Git
Getting Started with GitGetting Started with Git
Getting Started with Git
 
Git and Github workshop
Git and Github workshopGit and Github workshop
Git and Github workshop
 
Git the Docs: Learning Git in a safe space
Git the Docs: Learning Git in a safe spaceGit the Docs: Learning Git in a safe space
Git the Docs: Learning Git in a safe space
 
Git
GitGit
Git
 

More from Olaf Alders (6)

No Hugging, No Learning
No Hugging, No LearningNo Hugging, No Learning
No Hugging, No Learning
 
The MetaCPAN VM Part II (Using the VM)
The MetaCPAN VM Part II (Using the VM)The MetaCPAN VM Part II (Using the VM)
The MetaCPAN VM Part II (Using the VM)
 
The MetaCPAN VM for Dummies Part One (Installation)
The MetaCPAN VM for Dummies Part One (Installation)The MetaCPAN VM for Dummies Part One (Installation)
The MetaCPAN VM for Dummies Part One (Installation)
 
Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013
 
(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit(Ab)Using the MetaCPAN API for Fun and Profit
(Ab)Using the MetaCPAN API for Fun and Profit
 
Mangling
Mangling Mangling
Mangling
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Git submodule

  • 1. git submodule Olaf Alders olaf@wundercounter.com twitter.com/wundercounter Toronto Perl Mongers Sept 29, 2011
  • 2. What does it do? Git's submodule support allows a repository to contain, as a subdirectory, a checkout of an external project. Submodules maintain their own identity; the submodule support just stores the submodule repository location and commit ID, so other developers who clone the containing project ("superproject") can easily clone all the submodules at the same revision. Partial checkouts of the superproject are possible: you can tell Git to clone none, some or all of the submodules. source: "Git Community Book" http://book.git-scm.com/5_submodules.html
  • 3. An Example: mkdir shiny_app cd shiny_app/ git init mkdir inc mkdir -p root/static/js mkdir -p root/static/css echo "shiny app" > README git add . git commit -a -m "initial commit"
  • 4. Add a submodule git submodule add https://github.com/twitter/bootstrap.git inc/bootstrap git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: .gitmodules # new file: inc/bootstrap cat .gitmodules [submodule "inc/bootstrap"] path = inc/bootstrap url = https://github.com/twitter/bootstrap.git git commit -a -m "adds bootstrap as submodule"
  • 5. Link it up! mkdir root/static/css mkdir root/static/js ln -s inc/bootstrap/bootstrap.min.css root/static/css/ ln -s inc/bootstrap/js root/static/js/bootstrap git commit root -m "adds bootstrap symlinks"
  • 6. Now what? ● Work as you normally would ● Later, when you want to update bootstrap to the latest version cd inc/bootstrap git pull origin master cd ../.. git commit inc/bootstrap -m "updates bootstrap"
  • 7. Cloning repos with submodules When someone else clones your repo, they need to update and init: $ cd .. git clone shiny_app bootstrapper Cloning into bootstrapper... done. $ cd bootstrapper/ $ ls README inc root olaf-alderss-macbook-pro:bootstrapper olaf $ ls inc/bootstrap/ # no output above -- the inc/bootstrap folder is empty
  • 8. Remember to init and update We've got the repo, but the submodule is empty. Two commands will fix that. $ git submodule init Submodule 'inc/bootstrap' (https://github.com/twitter/bootstrap.git) registered for path 'inc/bootstrap' $ git submodule update Cloning into inc/bootstrap... remote: Counting objects: 3845, done. remote: Compressing objects: 100% (1430/1430), done. remote: Total 3845 (delta 2474), reused 3663 (delta 2329) Receiving objects: 100% (3845/3845), 1.04 MiB | 388 KiB/s, done. Resolving deltas: 100% (2474/2474), done. Submodule path 'inc/bootstrap': checked out '28c770bf679e131cc030c3bc4a1981450f831908'
  • 9. Is your HEAD detached? By default, the submodule in the cloned repo will not be on a branch: cd inc/bootstrap/ git branch * (no branch) master Try to remember to work on a branch before committing: $ git checkout master
  • 10. Oops! If you commit while not on a branch, you'll get the following "detached HEAD" message: $ git commit README.md -m "random change" [detached HEAD b92b798] random change 1 files changed, 3 insertions(+), 0 deletions(-) This is easy to recover from. Just check out a branch and merge the commit: $ git checkout master $ git merge b92b798
  • 11. git pull != git submodule update Team members should remember to change their workflow to: git pull origin master git submodule update Remember, a pull does not fetch submodule updates. To stay totally in sync, team members will want to update submodules as they pull.
  • 12. Caveat Merge conflicts If two team members commit the same submodule with differing HEADs, you will get a merge conflict. You will need to resolve this manually.
  • 13. What do you gain from submodules? ● You can build and test against bleeding edge checkouts ● You don't have to add someone else's code to your repo ● Team members can build against exactly the checkout you've built and tested against and vice versa ● Updating your submodules is trivial