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 7886151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:14:48+00:00 2026-06-03T05:14:48+00:00

Solution: remove –cached from git rm -r –cached submodule/name . Scripted for reference. I’m

  • 0

Solution: remove --cached from git rm -r --cached submodule/name. Scripted for reference.


I’m trying to remove a git submodule based on this SO answer, but the submodule is not being removed.

I add the submodule, commit the changes, then delete it using git rm -r --cached $path/to/submodule (minus the trailing / ), commit the changes, but the submodule is still there.

I can use rm -rf submodules/lift_sbt_24 to delete the folder and contents, but why isn’t git rm -r --cached doing that?

(deleting the relevant section from .gitmodules works fine, is no problem, hence not mentioned here)

This is git 1.7.5.4 on Ubuntu 11.10, fwiw. Complete example:

$> git submodule add git@github.com:lift-stack/lift_24_sbt.git submodules/lift_24_sbt
Adding submodule from repo git@github.com:lift-stack/lift_24_sbt.git as submodules/lift_24_sbt
Cloning into submodules/lift_24_sbt...
remote: Counting objects: 619, done.
remote: Compressing objects: 100% (375/375), done.
remote: Total 619 (delta 172), reused 593 (delta 147)
Receiving objects: 100% (619/619), 1.74 MiB | 112 KiB/s, done.
Resolving deltas: 100% (172/172), done.
$> git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commits.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   .gitmodules
#   new file:   submodules/lift_24_sbt
#
$> git add -a
$> git commit 'added submodules/lift_24_sbt'
[master 9894113] update
 2 files changed, 4 insertions(+), 0 deletions(-)
 create mode 160000 submodules/lift_24_sbt
$> git rm -r --cached submodules/lift_24_sbt
rm 'submodules/lift_24_sbt'
$> git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commits.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    submodules/lift_24_sbt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   submodules/lift_24_sbt/
$> git add -a
$> git commit -m 'deleted submodules/lift_24_sbt'
# On branch master
# Your branch is ahead of 'origin/master' by 1 commits.
#
nothing to commit (working directory clean)
$> ls -al submodules/lift_24_sbt/
total 1060
drwxr-xr-x 5 kurtosis kurtosis    4096 2012-04-18 17:26 ./
drwxrwxr-x 6 kurtosis kurtosis    4096 2012-04-18 17:26 ../
drwxrwxr-x 8 kurtosis kurtosis    4096 2012-04-18 17:32 .git/
drwxrwxr-x 2 kurtosis kurtosis    4096 2012-04-18 17:26 project/
drwxrwxr-x 3 kurtosis kurtosis    4096 2012-04-18 17:26 src/
-rw-rw-r-- 1 kurtosis kurtosis     931 2012-04-18 17:26 build.sbt
-rw-rw-r-- 1 kurtosis kurtosis     463 2012-04-18 17:26 .gitignore
-rw-rw-r-- 1 kurtosis kurtosis      91 2012-04-18 17:26 README.md
-rwxrwxr-x 1 kurtosis kurtosis     110 2012-04-18 17:26 sbt*
-rw-rw-r-- 1 kurtosis kurtosis     131 2012-04-18 17:26 sbt.bat
-rw-rw-r-- 1 kurtosis kurtosis 1041753 2012-04-18 17:26 sbt-launch.jar
$> git --version
git version 1.7.5.4
  • 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-03T05:14:49+00:00Added an answer on June 3, 2026 at 5:14 am

    What you’re seeing is correct; git rm --cached -r does not, in fact, remove the files from the working tree, only from the index. If you want git to remove the files from both the index and the working tree, you shouldn’t use --cached. See the git-rm man page for further information.


    Following is an explanation of what you did. I am assuming that you typed out the steps you took, rather than copying from a terminal; as far as I’m aware, git add -a is not a known git-add flag; I am also fairly sure you also meant git commit -m <message>.

    The cut-down steps you’ve taken:

    
    # First, add the submodule. 
    $> git submodule add git@github.com:lift-stack/lift_24_sbt.git submodules/lift_24_sbt
    # Check that the submodule exists. (It does). 
    $> git status
    # Add everything to the staging area from the working tree. 
    $> git add -a
    # Commit all changes. 
    $> git commit 'added submodules/lift_24_sbt'
    

    At this point, you’ve successfully added the module, and everything is working as expected.
    What you try to do next is to remove the module:

    $> git rm -r --cached submodules/lift_24_sbt
    

    Note: here, we do not remove the files from the working index, only from the index, because of the --cached:

    --cached
           Use this option to unstage and remove paths only from the index. Working tree
           files, whether modified or not, will be left alone.
    

    Then, check that we’ve removed the submodule:

    $> git status
    ... <snip> 
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   deleted:    submodules/lift_24_sbt
    

    As you can see, the submodule has been deleted, and everything is good. Note, however, that the files still exist in the working tree – you can still view them with ls. 🙂

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

Sidebar

Related Questions

I have came with solution to remove duplicates from generic list<T> in .NET 2.0
Can anyone suggest a good solution to remove duplicates from nested lists if wanting
My current solution for renaming the project folder is: Remove the project from the
I have been looking for an effective solution to remove duplicates from a C++
When I 'Remove' a project from a Visual Studio solution I often want to
I'm just trying to remove spaces from some line: (jan | feb | mar
I am looking for the clean, elegant and smart solution to remove namespacees from
Is there a better (faster) solution to remove duplicates from a comma separated string?
SOLUTION removeChild: function(select) { $(select).nextAll().remove(); } I am trying to dynamically create a chain
what's best solution using regex, to remove special characters from the begin and the

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.