Daniel Morrison

Git Submodules

Now that everyone’s on Git, people are starting to play with submodules.

Here’s why you should too.

Just like svn:externals

Just like Piston

This sounds kinda confusing, and at least one aspect is probably not what you expect.

Example

For MicroRevie.ws, I wanted to add Rails as a submodule, as I like living on the edge. I used Koz’s version on GitHub (since the official Rails git repo isn’t yet available), so in my git project I typed:

<pre>git submodule add git://github.com/NZKoz/koz-rails.git vendor/rails</pre>

This tells git where the code is from (remember, this could be local too) and where I want it to live.

If I then run git status I’ll see a new file called .gitmodules. The file looks like:

<pre>[submodule "vendor/rails"] path = vendor/rails url = git://github.com/NZKoz/koz-rails.git</pre>

Fantastic! Once I git add and git commit the files, they’re locked into my repository. They are not stored in my repository, however, just references. When I push the main MicroRevie.ws project up to GitHub, it small and fast (better than Piston!).

When Matt pulls down his copy of the project, he needs to run these two commands to use the submodules:

<pre>git submodule init git submodule update</pre>

Updating a submodule

Here’s where submodules are more like Piston. You must explicitly update submodules. Here are the steps:

<pre>cd vendor/rails git pull cd - git commit -a </pre>

Or in English: go into the submodule, pull updates, then get out and commit.

When you commit, you are again only committing a change in reference. You’re not storing tons of new updates, just a reference to the new revision. You can even go backwards, but that’s left as an exercise for the reader.

When Matt wants to get my changes, he can’t just do a git pull. He has to also type:

<pre>git submodule update</pre>

And he’ll be updated to the version I committed.

Is it worth it?

Yes. However, I’ve defended (and simultaneously cursed) svn:externals, so I’m not the final judge.

In the end though, I really like git submodules better than either externals or Piston. For me it comes down to:

Try them out. At worst, you’ll remove the references and be out a few minutes of your time.

27 Comments

  1. Mark Van Holstyn — April 08, 2008

    Thanks for the info on submodules Dan. Just a slight correction in regards to SVN externals though. Externals do allow you to specify which revision you want to be tied to, for example:

    rails -r9243 http://svn.rubyonrails.org/rails/trunk

  2. Daniel Morrison — April 09, 2008

    Mark,

    Good point. Maybe I’m too hard on svn, by only pointing to the common (non-version-specified) use case.

  3. Ryan McGeary — April 12, 2008

    Daniel, Good post, but isn’t there a small advantage to a piston or braid-like approach where all the files are in your own repository? What happens during deployments? Doesn’t the deployment now rely on a possible many remote repositories to succeed? Consider both vendor/rails and a possible many vendor/plugins each with their own submodule.

    I think I also missed an important point. How does Matt’s git submodule update avoid pulling a later version of edge rails than the original revision that you intended? The .gitmodules file only seems to specify the public clone url without any commit revision.

  4. Daniel Morrison — April 12, 2008

    Good comments, Ryan. I posted a follow-up.

  5. RFID Reader — April 16, 2010

    great information you write it very clean. I’m very lucky to get

    this details from you.

  6. problems with yaz — May 02, 2013

    It’s really very complex in this active life to listen news on TV, thus I simply use the web for that purpose, and take the hottest information.

  7. شركة تنظيف بالدمام — May 03, 2023

    يجب أن يكون لكل عمل نوع من الأولوية ، بما في ذلك تنظيف المنزل وصيانته. يمكن النظر إلى هذا على أنه مشروع مستمر له معالم مثل التنظيف الربيعي أو التنظيف قبل الموسم أو التجديدات.
    على سبيل المثال ، يعد إنشاء قائمة مراجعة لتنظيف المنزل تتضمن مهامًا فردية لأفراد مختلفين من العائلة ، مثل تنظيف شخص بالمكنسة الكهربائية كل ثلاثاء وجمعة وشخص آخر يقوم بتنظيف حوض الاستحمام كل أسبوع ، طريقة رائعة للحفاظ على تنظيم الأشياء. وهي طريقة رائعة للبقاء منظمًا.
    اصنع محلول التنظيف الخاص بك
    هل تعلم أن مطبخك يحتوي بالفعل على بعض أدوات وحيل التنظيف الرائعة مثل:
    يمكنك تنظيف وتجديد الكثير من الأشياء بالليمون.
    إزالة الروائح الكريهة بالليمون والملح الخشن.
    أضف الملح الخشن إلى سلة المهملات لإزالة الروائح الكريهة.
    قم بالتنظيف باستخدام عناصر غير متوقعة
    يمكنك استخدام فرشاة أسنان لتنظيف الأوساخ من التجاويف وأنابيب النوافذ المصنوعة من الألومنيوم ، أو وضع جوربًا شفافًا في رأس المكنسة لالتقاط الأشياء الصغيرة أسفل الأثاث.
    استخدم مكنسة كهربائية
    للمكانس الكهربائية استخدامات عديدة ، مثل تنظيف المفروشات والمراتب ، وإزالة الغبار عن الخزائن ، وإزالة بقايا التوابل من أرفف المطبخ.
    أدوات التنظيف والتنظيف
    تأكد من أن المماسح والمكانس وزجاجات الرش ومستلزمات التنظيف الأخرى في حالة جيدة وجاهزة للاستخدام. يمنع تراكم الروائح والعفن والبكتيريا على أدواتك.

  8. rosydam — May 26, 2023

    Kudos to the author for Pokemon Infinite Fusion the engaging and thought-provoking read.

  9. ankerman — May 27, 2023

    I want to extend a heartfelt thank you for sharing this Pokemon Infinite Fusion resource. It has made a significant difference in my understanding.

  10. bulbass — June 09, 2023

    Your article has given me a lot of positive energy, Pokemon Fusion thanks

  11. sam — June 28, 2023

    I want to extend a heartfelt thank you for sharing this Pokemon Infinite Fusion resource. Isubway surferst has made a significant difference in my understanding.

  12. sam — June 28, 2023

    I want to extend a heartfelt thank you for sharing this Pokemon Infinite Fusion resource. Isubway surferst has made a significant dif jhgta gameference in my understanding.

  13. jimmiz — July 03, 2023

    The model is quite good with Dynamons World

  14. Smith Leo — July 05, 2023

    One important heardle aspect to note is that submodules are not stored directly in your repository. Instead, they are referenced by their location, which can be either a local or remote URL. This means that when you clone a repository with submodules, you’ll need to initialize and update the submodules separately to fetch their content.

  15. Kathy Barrera — July 13, 2023

    This implies that you must initialize and update each submodule independently in order to collect its content when you clone a repository that has them. doodle jump

  16. Michael Bedolla — July 17, 2023

    You have generated information for the present period and made people aware that everything is moving online and more and more people are now preferring online learning. Shopping may also be done online and if you must this MadHappy x Dodgers I LOVE LA Hoodie is a great option.

  17. Delia Hopkins — July 18, 2023

    I ve read everything you ve written on this topic and I dont feel like I ve wasted my time reading it so I appreciate it and this Matt Damon Good Will Hunting Red Cobra Jacket because it has supported me a lot in winter and you must also wear it in winter.

  18. Kara — July 20, 2023

    I really like the information you share. I learned a lot of new and useful knowledge from your post. slither io

  19. Jennifer Connelly — July 22, 2023

    Every fan may discover the ideal attire thanks to the thoughtful design of our Comic Con Jackets which are made to meet a variety of interests. We have the ideal jacket to help you display your love at an unbelievable price whether you’re a super hero or a celebrity fan.

  20. miksoal — July 24, 2023

    Whether you’re a super hero or a follower of a famous person, we have the perfect jacket to let you show your support at a price that’ll blow your mind.
    puppet hockey

  21. bensonclark — July 24, 2023

    I am studying at a medical school and at the same time I work part-time in a cosmetology company. It is almost impossible for me to combine all this. Especially to devote enough time to study. Recently, write my assignment we were asked an essay and I decided that it would be best and easiest to buy it, click this over here now, maybe it will be useful to you sometime.

  22. kyliemontigo — July 25, 2023

    Show some love if you are a real fan of today trending attire and want to wear your best attire through best online platform. Here is the best platform for you Barbie 2023 Premiere Margot Robbie Pink Jacket

  23. And Just Like That Outfits  — July 27, 2023

    Your blog post resonated with me on a personal level. I could relate to the experiences you described and found comfort in knowing that others have gone through similar challenges. Thank you for sharing your story. And Just Like That Outfits 

  24. christome — August 03, 2023

    If you know anything about fashion, please share your wisdom with me. I recommend wearing this Kevin Hart Killing With Comedy Hoodie during the cold season. The market is highly stylish, and these coats are well-made.

  25. CVBs — August 04, 2023

    The way you addressed the common misconceptions about this topic was spot on. Great job! CVBs

  26. Loki Costume — August 07, 2023

    “I agree with your point about [insert topic], but I also think it’s important to consider [insert opposing viewpoint]. Do you have any thoughts on that?” Loki Costume

  27. halloween costumes — August 10, 2023

    “Great job on this project! I really appreciate the effort you put into it. Your hard work paid off and it shows in the final product.” halloween costumes