LinuxCommandLibrary

git-delete-submodule

Remove a submodule from a Git repository

TLDR

Delete a specific submodule

$ git delete-submodule [path/to/submodule]
copy

SYNOPSIS

git-delete-submodule [-f] <path>

PARAMETERS

-f
    Force deletion without confirmation prompts

<path>
    Relative or absolute path to the submodule directory

DESCRIPTION

The git-delete-submodule command is a non-standard, community-developed helper script or alias for Linux environments that simplifies the removal of Git submodules. Standard Git lacks a single command for this; instead, it requires multiple steps: deinitializing the submodule, removing it from the index, deleting the directory, cleaning the .git/modules entry, and updating .gitmodules.

This script automates these steps into one invocation, reducing errors and saving time for developers managing complex repositories with submodules. It typically prompts for confirmation unless forced, ensuring safe operation. Widely shared on GitHub and forums since around 2012, it's invoked as a Git extension but must be installed separately (e.g., via curl or manual script download).

Usage is straightforward for any submodule path, making it a popular alternative to manual commands.

CAVEATS

Not part of core Git; requires manual installation. Always commit changes afterward. May fail if submodule has uncommitted changes or is in use.

AUTOMATED STEPS

1. git submodule deinit -f <path>
2. git rm -f <path>
3. rm -rf .git/modules/<path>
4. Remove entry from .gitmodules
5. git commit

INSTALLATION EXAMPLE

curl -o /usr/local/bin/git-delete-submodule https://raw.githubusercontent.com/.../script.sh
chmod +x /usr/local/bin/git-delete-submodule

HISTORY

Emerged in early 2010s as community scripts (e.g., GitHub gists by users like @alexheretic) to address Git's verbose submodule removal process introduced in Git 1.5.3 (2007). Gained popularity with Git 2.x improvements but remains unofficial.

SEE ALSO

git-submodule(1), git-rm(1), rm(1)

Copied to clipboard