DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Developer Git Commit Hygiene
  • A Comprehensive Guide to GitHub
  • Mastering Git
  • Understanding Git

Trending

  • MySQL to PostgreSQL Database Migration: A Practical Case Study
  • Securing the Future: Best Practices for Privacy and Data Governance in LLMOps
  • System Coexistence: Bridging Legacy and Modern Architecture
  • Start Coding With Google Cloud Workstations
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Keeping Submodules Up to Date in Git

Keeping Submodules Up to Date in Git

When your project gets complicated, it makes sense to split it up into manageable chunks. Git supports this process using submodules.

By 
Tim Myerscough user avatar
Tim Myerscough
·
Dec. 05, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
9.2K Views

Join the DZone community and get the full member experience.

Join For Free

When your project gets complicated, it makes sense to split it up into manageable chunks. Git supports this process using submodules.

When you create a reference to a submodule within your repository, you actually include a reference to a specific commit. If the repository you are referencing is updated, those changes aren’t automatically reflected in your repository. This sort of makes sense, since git has no idea whether the submodule you are referencing is under your control or not.

By default, the submodule is checked out in a detached head state. This is fine if you want a read-only copy, but a bit of a pain if you want to commit changes. In addition, by default, submodules aren’t updated when you pull changes to your repository meaning you can get out of sync.

Working with submodules on a specific branch, where you want to commit changes to the submodule, requires a slight change to your CLI commands. Because you are no longer working with one repository, but multiple repositories.

Creating Your Submodule

Create your submodule, pointing it to the destination branch

git submodule add -b <branch> <repository_url> <submodule_folder>

Track the Remote Branch

Once you have your submodule, and you are checked out on a branch, you need to ensure that it is configured to track the remote branch of the submodule

cd <submodule_folder>
git branch --set-upstream-to=origin/<branch>

Now you are tracking the remote branch. You can make changes to the sub-module, and push them to the remote repository as required.

Updating Your Repository (Including Submodules)

When you make changes to your submodule, then you need to commit the change in the parent to ensure that the pointer is kept up to date. However, this results in two commits - one to the submodule and one to the parent, and this may not always be desirable at the same time.

In order to ensure the submodules are up to date, when pulling changes, use the following commands:

cd <parent_repository>
git pull
git submodule foreach git pull

This will ensure that the repository and submodules are kept up to date on the appropriate branch.

Git Repository (version control)

Opinions expressed by DZone contributors are their own.

Related

  • Developer Git Commit Hygiene
  • A Comprehensive Guide to GitHub
  • Mastering Git
  • Understanding Git

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!