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

  • SEARCH
  • Home
  • 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 8018069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:02:01+00:00 2026-06-04T21:02:01+00:00

How do I get rid of submodules when switching branches. I do not understand

  • 0

How do I get rid of submodules when switching branches. I do not understand why git clean says it removed the submodule but does not. Is this a bug? Below are cut&paste steps to reproduce.

git --version
git version 1.7.8.4

git init submod
cd submod
echo "This is a submodule" > README.txt
git add .
git commit -m "Initial commit"
cd ..
git init prog
cd prog
echo "This is a program" > README.txt
git add .
git commit -a -m "Initial commit"
git checkout -b topic1
git submodule add ../submod
git commit -m "Added submodule"

git checkout master
#warning: unable to rmdir submod: Directory not empty
#Switched to branch 'master'

git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       submod/
#nothing added to commit but untracked files present (use "git add" to track)

git clean -fd
#Removing submod/

git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       submod/
#nothing added to commit but untracked files present (use "git add" to track)
  • 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-06-04T21:02:02+00:00Added an answer on June 4, 2026 at 9:02 pm

    This isn’t a bug, it’s documented behaviour. From man git-clean:

    If an untracked directory is managed by a different git repository, it is not removed by default.

    The submod directory is a different git repository; if you want to remove it, Use -f option twice if you really want to remove such a directory.

    git clean -f -f -d submod does remove submod. See my steps below (almost identical; different git version and hard-coded submodule path because otherwise git spits the dummy).


    Steps

    
    $ git --version
    git version 1.7.5.4 # Note, different git-version. 
    

    Make the two repositories

    
    git init submod
    cd submod
    echo "This is a submodule" > README.txt
    git add .
    git commit -m "Initial commit"
    cd ..
    git init prog
    cd prog
    echo "This is a program" > README.txt
    git add .
    git commit -a -m "Initial commit"
    

    Add submod as a git submodule in topic1 branch.

    
    git checkout -b topic1
    git submodule add /Users/simont/sandbox/SOTESTING/Subdir-testing/submod
    git commit -m "Added submodule"
    

    Now for the interesting section.

    
    $ git checkout master
    warning: unable to rmdir submod: Directory not empty
    Switched to branch 'master'
    
    git status
    # On branch master
    # Untracked files:
    #   (use "git add ..." to include in what will be committed)
    #
    #       submod/
    #nothing added to commit but untracked files present (use "git add" to track)
    

    Attempt to git-clean, then actually git-clean.

    
    git clean -fd
    #Removing submod/
    
    git status
    # On branch master
    # Untracked files:
    #   (use "git add ..." to include in what will be committed)
    #
    #       submod/
    #nothing added to commit but untracked files present (use "git add" to track)
    
    $ # As we can see, we haven't actually removed anything yet. 
    $ ls
    README.txt  submod
    
    $ git clean -f -f -d submod
    Removing submod/
    
    $ ls
    README.txt
    
    $ git status
    # On branch master
    nothing to commit (working directory clean)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to get rid of untracked content in Git's submodules. Running git
I want to get rid of this... BUT only for one project from solution..
I keep trying to get rid of this keybinding but setting it to nil
I am trying to get rid of this: document.body.className = someclass; I want to
How can I get rid of this error and other while compiling the below
I want to get rid of the CIDR notation and tried the following, but
I want to get rid of the default css stylesheet app/assets/stylesheets/scaffold.css.scss but when I
How to get rid of this, I am using the Google compatibility library for
We'd like to get rid of NHibernate for something like Massive, PetaPoco, etc. but
I am trying to get rid of cookies. For SEO reasons I do not

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.