0Pricing
Git Advanced: Monorepo, Submodules & Workflows · レッスン

サブモジュールの削除と初期化解除

初期化解除、.gitmodulesのクリーンアップ、残った状態の回避を含め、Gitサブモジュールをリポジトリから完全かつ正しく削除する手順を学びます。

「サブモジュールの削除と初期化解除」はCoddyKit上の無料Git Advanced: Monorepo, Submodules & Workflowsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはGit Advanced: Monorepo, Submodules & Workflows学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Git Advanced: Monorepo, Submodules & Workflowsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.

よくある質問

「サブモジュールの削除と初期化解除」レッスンは無料ですか?

はい。「サブモジュールの削除と初期化解除」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Git Advanced: Monorepo, Submodules & Workflowsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Git Advanced: Monorepo, Submodules & Workflowsコースには全4レッスンが含まれています。

「サブモジュールの削除と初期化解除」で何を学びますか?

初期化解除、.gitmodulesのクリーンアップ、残った状態の回避を含め、Gitサブモジュールをリポジトリから完全かつ正しく削除する手順を学びます。 ブラウザで直接実行するハンズオンコードでGit Advanced: Monorepo, Submodules & Workflowsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Git Advanced: Monorepo, Submodules & Workflowsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのGit Advanced: Monorepo, Submodules & Workflowsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「サブモジュールの削除と初期化解除」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このGit Advanced: Monorepo, Submodules & Workflowsレッスンでコードを書いて実行できますか?

はい。すべてのGit Advanced: Monorepo, Submodules & Workflowsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Git Submodules入門
  2. Submodulesの追加とクローン
  3. Submodulesの更新と同期
  4. サブモジュールの削除と初期化解除
← Git Advanced: Monorepo, Submodules & Workflowsに戻る