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

Subtree Splitによる変更のアップストリームへの反映

サブツリー内で行った変更を抽出し、git subtree splitとpushを使って元のアップストリームリポジトリへ反映する方法を学びます。

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

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

Two-Way Subtree Workflows

Subtree is not just for pulling code in. One of its strengths is the ability to contribute changes back to the original project. This makes subtree a genuine two-way integration tool.

The key command is git subtree push, powered internally by git subtree split.

What 'split' Does

git subtree split walks your history and produces a synthetic branch containing only the commits that touched the subtree's prefix, rewritten as if that folder were the repo root.

This is what makes the changes mergeable back upstream.

Recap: Adding a Subtree

Assume you added an upstream library under vendor/widget earlier. Now you have made improvements there and want to share them.

git subtree add --prefix=vendor/widget \
  https://example.com/widget.git main --squash

Creating the Split Branch

Run split to create a branch with just the subtree's history rebased to the prefix root.

git subtree split --prefix=vendor/widget -b widget-upstream

Inspecting the Split

Check out the split branch and confirm its files live at the root, not under vendor/widget. This proves the rewrite worked.

git log --oneline widget-upstream
git ls-tree --name-only widget-upstream

Pushing the One-Step Way

You can split and push in a single command. git subtree push does the split internally and pushes the result to the upstream remote and branch.

git subtree push --prefix=vendor/widget \
  https://example.com/widget.git contrib-branch

Opening a Pull Request

Push to a feature branch on a fork you control, then open a pull request upstream. Your subtree commits appear as ordinary commits on that project, ready for review.

Keeping Splits Fast

On large histories, split can be slow because it re-walks commits. Subtree caches rewrites; passing --rejoin writes a merge commit so future splits start from there.

git subtree split --prefix=vendor/widget --rejoin

Avoiding Mixed Commits

Split works cleanly only when commits are scoped. A commit touching both the subtree and unrelated app code becomes awkward upstream. Keep subtree changes in their own focused commits.

When to Push Back

Push upstream when your fixes are general-purpose and the maintainers accept contributions. For private, repo-specific tweaks, keep them local and never push them back.

Pulling Their Acceptance Back

After upstream merges your contribution, pull it back into the subtree so your superproject and the original project converge again, closing the round trip.

git subtree pull --prefix=vendor/widget \
  https://example.com/widget.git main --squash

Quick Check

Test your understanding of subtree split and push.

Recap

You learned the two-way subtree workflow: split isolates subtree commits into a prefix-rooted branch, push sends them upstream in one step, --rejoin speeds up repeated splits, and keeping commits focused makes upstream contribution clean.

よくある質問

「Subtree Splitによる変更のアップストリームへの反映」レッスンは無料ですか?

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

「Subtree Splitによる変更のアップストリームへの反映」で何を学びますか?

サブツリー内で行った変更を抽出し、git subtree splitとpushを使って元のアップストリームリポジトリへ反映する方法を学びます。 ブラウザで直接実行するハンズオンコードでGit Advanced: Monorepo, Submodules & Workflowsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「Subtree Splitによる変更のアップストリームへの反映」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. Git Subtree入門
  2. Subtreeの追加とマージ
  3. SubtreeとSubmoduleの比較
  4. Subtree Splitによる変更のアップストリームへの反映
← Git Advanced: Monorepo, Submodules & Workflowsに戻る