Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:18:40+00:00 2026-05-26T07:18:40+00:00

Judging just from the number of results for git submodule here on SO alone,

  • 0

Judging just from the number of results for “git submodule” here on SO alone, this is clearly a commonly asked and easily confused topic, so I will try to be as precise as possible.

Forgetting everything about updating/committing/branching submodules (which I understand greatly complicates things), why do submodules get emptied each time I change branches? From my current understanding, this makes branches expensive; what if I’m at the airport, and can’t easily/cheaply connect? Am I doing something wrong, or there’s some development philosophy that I’m not yet aware of?

Examples never hurt:

## make a new project
$> git --version
git version 1.7.5.4
$> mkdir new_proj; cd new_proj; git init
$> touch new_file_1.txt; touch new_file_2.txt
$> git add . && git commit -m "first commit"

## move into some development branch
$> git checkout -b cool_feature
$> <hack hack hack>
# in the middle, I add a submodule
$> git submodule add https://github.com/some/other_proj.git other_proj
$> git submodule update --init
$> ls -lR
new_file_1.txt
new_file_2.txt
other_proj
other_proj/that_file
other_proj/another_file

## I have to go back to master to do some work
$> git checkout master
# Why is other_proj still around?
$> git status
Untracked: other_proj
## Fine, I'll remove it, since I want a clean working copy, because I need to do some work and commits
$> git clean -f -d
$> <work work work>

## Now I'm ready to go back to cool_feature, but my submodules are empty!
$> git checkout cool_feature

At this point, I’m supposed to git submodule update, but what if I can’t/it’s expensive (e.g. it’s remote, and I don’t have internet access/it’s slow).

The best workaround I’ve come up with is to clone all the submodules that I care about into a completely separate location, and then submodule from my local clones; this preserves the cheapness of submodules. Of course, this adds another layer of complexity when you’re working on a team. :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:18:40+00:00Added an answer on May 26, 2026 at 7:18 am

    Considering a submodule is nothing more than a pointer to a commit of another repo, the git submodule update is a bit unavoidable (in order to get back the content associated with said pointer).

    One other workaround would be to clone your main repo:

    • one for the cool_feature branch, where you have your submodules
    • one for the master branch, where you don’t have any submodules

    Switching from one branch to another wouldn’t require a git checkout (and its associated git submodule update), but a change of path.

    The other workaround, if you want to work in one directory, has been described in “Replaced third party code with git submodules, now I can’t switch branches“

    move the submodule directory out of the way before switching to the master branch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to attach multiple Behaviors to an UIElement (which, just judging from the
Judging from this Wikipedia article on cipher modes and other things I've heard about
The default Cassandra systems keyspace system is present in all Cassandra installations. Judging from
Judging from the result of my last inquiry , I need to calculate and
Judging from the title, I kinda did my program in a fairly complicated way.
As detailed here and confirmed here , the default number of rows Oracle returns
I just updated Intel C++ from 12.0 to 12.1. I uninstalled the 12.0 from
So I developed this access database application (just the back end), on a lap
Judging by the # of javascript inheritance questions here I am going to assume
I have a block of html like this. Judging by the background color of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.