0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Lección

Eliminación y desinicialización de submódulos

Aprenda el procedimiento correcto y completo para eliminar un submódulo de Git de un repositorio, incluida su desinicialización, la limpieza de .gitmodules y la prevención de estados residuales.

Eliminación y desinicialización de submódulos es una lección gratuita de Git Advanced: Monorepo, Submodules & Workflows en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Git Advanced: Monorepo, Submodules & Workflows, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Git Advanced: Monorepo, Submodules & Workflows incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

When You Need to Remove a Submodule

Submodules are added to pull in external code, but requirements change. You may need to remove one when the dependency is replaced, vendored directly, or simply no longer needed.

Removal is more involved than deleting a folder: a submodule lives in several places at once, and missing one leaves your repo in a broken state.

Where a Submodule Lives

A submodule has three footprints:

  • .gitmodules — the declarative config
  • .git/config — your local active config
  • .git/modules/<path> — the cached submodule git data

Plus the working tree folder itself. Clean removal touches all of these.

Step 1: Deinitialize

Start with git submodule deinit. This unregisters the submodule and removes its entry from .git/config, leaving the rest intact for now.

git submodule deinit -f path/to/submodule

Step 2: Remove from the Index

Use git rm to remove the submodule from tracking and from the working tree. This also updates .gitmodules automatically in modern Git.

git rm -f path/to/submodule

Step 3: Clean the Cached Git Data

The submodule's git data lingers under .git/modules. Remove it so a future submodule with the same path does not collide.

rm -rf .git/modules/path/to/submodule

Verify .gitmodules Is Clean

Open .gitmodules and confirm the [submodule "..."] block is gone. If git rm left an empty file or a stale entry, fix it by hand and stage the change.

git diff --cached .gitmodules

Step 4: Commit the Removal

The removal must be committed so collaborators get the change. The commit captures the deleted folder, the updated .gitmodules, and the dropped index entry.

git commit -m 'Remove path/to/submodule'

The Manual Fallback

On older Git versions git rm may not edit .gitmodules for you. The manual path:

git config -f .gitmodules --remove-section submodule.path/to/submodule
git add .gitmodules
git rm --cached path/to/submodule
rm -rf path/to/submodule

What Collaborators See

When teammates pull the removal commit, the folder disappears from tracking. But their local .git/modules cache and .git/config entry may persist. Tell them to run git submodule sync and clean up if needed.

Common Mistakes

  • Deleting only the folder with rm -rf — leaves a broken index entry
  • Forgetting .git/modules cleanup — blocks re-adding the same path
  • Not committing the .gitmodules change — others still see the submodule

A Reusable Checklist

Whenever you remove a submodule, run through: deinit, rm, clean modules cache, verify .gitmodules, commit. Following the same order every time prevents the half-removed states that confuse a whole team.

Quick Check

Test your understanding of removing submodules.

Recap

You learned the complete removal procedure: deinit to unregister, git rm to drop tracking, clean .git/modules to clear the cache, verify .gitmodules, then commit. Following this checklist every time keeps both your repo and your collaborators' clones healthy.

Preguntas frecuentes

¿La lección «Eliminación y desinicialización de submódulos» es gratis?

Sí — el texto completo de «Eliminación y desinicialización de submódulos» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Git Advanced: Monorepo, Submodules & Workflows, actualiza a CoddyKit PRO. El curso de Git Advanced: Monorepo, Submodules & Workflows incluye 4 lecciones en total.

¿Qué aprenderé en «Eliminación y desinicialización de submódulos»?

Aprenda el procedimiento correcto y completo para eliminar un submódulo de Git de un repositorio, incluida su desinicialización, la limpieza de .gitmodules y la prevención de estados residuales. Practicas Git Advanced: Monorepo, Submodules & Workflows con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Git Advanced: Monorepo, Submodules & Workflows?

No se requiere experiencia previa. Git Advanced: Monorepo, Submodules & Workflows en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Eliminación y desinicialización de submódulos»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Git Advanced: Monorepo, Submodules & Workflows?

Sí. Cada lección de Git Advanced: Monorepo, Submodules & Workflows incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Introducción a los submódulos de Git
  2. Añadir y clonar submódulos
  3. Actualizar y sincronizar submódulos
  4. Eliminación y desinicialización de submódulos
← Volver a Git Advanced: Monorepo, Submodules & Workflows