Skip to main content

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

--remove-section mode was deprecated and replaced by command remove-section as per https://git-scm.com/docs/git-config#_deprecated_modes
Source Link
Jan Dolejsi
  • 1.6k
  • 15
  • 28

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

Make the old stuff more obviously old -- LLMs are still picking up that advice and handing it out.
Source Link
Stabledog
  • 3.4k
  • 2
  • 35
  • 43

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Older community wiki instructions:

Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Older community wiki instructions:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

In modern git (I'm writing this in 2022, with an updated git installation), this has become quite a bit simpler:

  • Run git rm <path-to-submodule>, and commit.

This removes the filetree at <path-to-submodule>, and the submodule's entry in the .gitmodules file. I.e. all traces of the submodule in your repository proper are removed.

As the docs note however, the .git dir of the submodule is kept around (in the modules/ directory of the main project's .git dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/, and remove the submodule's entry in the file .git/config. These steps can be automated using the commands

  • rm -rf .git/modules/<path-to-submodule>, and
  • git config --remove-section submodule.<path-to-submodule>.


Caution: content below is older community wiki instructions. Ignore if you have a modern git:

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.

update for 2022 -- it's way easier now
Source Link
Tomas
  • 4.5k
  • 2
  • 18
  • 10
Loading
added explanations and consistency of format (line breaks before commands)
Source Link
Michael Cox
  • 1.3k
  • 2
  • 15
  • 24
Loading
added parenthesis for clarity
Source Link
Michael Cox
  • 1.3k
  • 2
  • 15
  • 24
Loading
add link to alternative steps which aren't as cumbersome as this one
Source Link
kaartic
  • 523
  • 6
  • 24
Loading
deleted 51 characters in body
Source Link
John Douthat
  • 41.3k
  • 11
  • 71
  • 67
Loading
adding this according to a the answer below
Source Link
Jossef Harush Kadouri
  • 34.6k
  • 10
  • 143
  • 133
Loading
Added commit command with syntax
Source Link
Manav Kataria
  • 5.4k
  • 5
  • 26
  • 26
Loading
not submodule name. It is the submodule path.
Source Link
dhilipsiva
  • 3.7k
  • 1
  • 26
  • 35
Loading
added istruction to stage the .gitmodules changes
Source Link
jackslash
  • 8.6k
  • 47
  • 56
Loading
This must be done *after*, or on my system it causes git to freak out saying the module being referenced doesn't exist
Source Link
Chris Down
  • 1.8k
  • 1
  • 17
  • 27
Loading
added 48 characters in body
Source Link
John Douthat
  • 41.3k
  • 11
  • 71
  • 67
Loading
deleted 51 characters in body; Post Made Community Wiki
Source Link
John Douthat
  • 41.3k
  • 11
  • 71
  • 67
Loading
Added a needed step mentioned a few times in the comments for this answer
Source Link
Loading
Named the link.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
Update to reflect the extra step as written on the wiki page, + add section anchor to the wiki page (it is the last section on a very long page, not obvious at first)
Source Link
Loading
deleted 15 characters in body
Source Link
John Douthat
  • 41.3k
  • 11
  • 71
  • 67
Loading
Replaced line with section in the first bullet point.
Source Link
Loading
added 28 characters in body
Source Link
John Douthat
  • 41.3k
  • 11
  • 71
  • 67
Loading
Bounty Awarded with 50 reputation awarded by CommunityBot
formatting
Source Link
philfreo
  • 44.2k
  • 27
  • 131
  • 142
Loading
Source Link
John Douthat
  • 41.3k
  • 11
  • 71
  • 67
Loading