Submodule entfernen und deinitialisieren
Lernen Sie das korrekte und vollständige Vorgehen zum Entfernen eines Git-Submoduls aus einem Repository kennen – einschließlich Deinitialisierung, Bereinigung von .gitmodules und dem Vermeiden zurückbleibender Zustände.
Submodule entfernen und deinitialisieren ist eine kostenlose Git Advanced: Monorepo, Submodules & Workflows-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Git Advanced: Monorepo, Submodules & Workflows-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Git Advanced: Monorepo, Submodules & Workflows-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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/submoduleStep 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/submoduleStep 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/submoduleVerify .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 .gitmodulesStep 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/submoduleWhat 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/modulescleanup — blocks re-adding the same path - Not committing the
.gitmoduleschange — 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.
Häufig gestellte Fragen
Ist die Lektion „Submodule entfernen und deinitialisieren“ kostenlos?
Ja — der vollständige Text von „Submodule entfernen und deinitialisieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Git Advanced: Monorepo, Submodules & Workflows-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Git Advanced: Monorepo, Submodules & Workflows-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Submodule entfernen und deinitialisieren“?
Lernen Sie das korrekte und vollständige Vorgehen zum Entfernen eines Git-Submoduls aus einem Repository kennen – einschließlich Deinitialisierung, Bereinigung von .gitmodules und dem Vermeiden zurüc… Du übst Git Advanced: Monorepo, Submodules & Workflows mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Git Advanced: Monorepo, Submodules & Workflows zu starten?
Keine Vorkenntnisse erforderlich. Git Advanced: Monorepo, Submodules & Workflows auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Submodule entfernen und deinitialisieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Git Advanced: Monorepo, Submodules & Workflows-Lektion Code schreiben und ausführen?
Ja. Jede Git Advanced: Monorepo, Submodules & Workflows-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Einführung in Git-Submodule
- Submodule hinzufügen und klonen
- Submodule aktualisieren und synchronisieren
- Submodule entfernen und deinitialisieren