Отправка изменений обратно в исходный репозиторий через разделение поддерева
Узнайте, как извлекать изменения, внесённые внутри поддерева, и отправлять их обратно в исходный репозиторий с помощью git subtree split и push.
«Отправка изменений обратно в исходный репозиторий через разделение поддерева» — бесплатный урок Git Advanced: Monorepo, Submodules & Workflows на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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 --squashCreating 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-upstreamInspecting 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-upstreamPushing 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-branchOpening 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 --rejoinAvoiding 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 --squashQuick 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.
Часто задаваемые вопросы
Урок «Отправка изменений обратно в исходный репозиторий через разделение поддерева» бесплатный?
Да — полный текст урока «Отправка изменений обратно в исходный репозиторий через разделение поддерева» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Git Advanced: Monorepo, Submodules & Workflows, подпишись на CoddyKit PRO. Курс Git Advanced: Monorepo, Submodules & Workflows содержит 4 уроков всего.
Чему я научусь в уроке «Отправка изменений обратно в исходный репозиторий через разделение поддерева»?
Узнайте, как извлекать изменения, внесённые внутри поддерева, и отправлять их обратно в исходный репозиторий с помощью git subtree split и push. Ты практикуешь Git Advanced: Monorepo, Submodules & Workflows с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Git Advanced: Monorepo, Submodules & Workflows?
Предыдущий опыт не требуется. Git Advanced: Monorepo, Submodules & Workflows на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.
Сколько времени занимает урок «Отправка изменений обратно в исходный репозиторий через разделение поддерева»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Git Advanced: Monorepo, Submodules & Workflows?
Да. Каждый урок Git Advanced: Monorepo, Submodules & Workflows включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Введение в Git Subtree
- Добавление и объединение с помощью Subtree
- Сравнение Subtree и Submodule
- Отправка изменений обратно в исходный репозиторий через разделение поддерева