Wysyłanie zmian z powrotem do upstream za pomocą subtree split
Poznaj sposób wyodrębniania zmian wprowadzonych w subtree i wysyłania ich z powrotem do oryginalnego repozytorium upstream za pomocą git subtree split i push.
Wysyłanie zmian z powrotem do upstream za pomocą subtree split to bezpłatna lekcja Git Advanced: Monorepo, Submodules & Workflows na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Git Advanced: Monorepo, Submodules & Workflows, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Git Advanced: Monorepo, Submodules & Workflows zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Wysyłanie zmian z powrotem do upstream za pomocą subtree split” jest bezpłatna?
Tak — pełny tekst „Wysyłanie zmian z powrotem do upstream za pomocą subtree split” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Git Advanced: Monorepo, Submodules & Workflows, przejdź na CoddyKit PRO. Kurs Git Advanced: Monorepo, Submodules & Workflows zawiera 4 lekcji w sumie.
Co nauczysz się w „Wysyłanie zmian z powrotem do upstream za pomocą subtree split”?
Poznaj sposób wyodrębniania zmian wprowadzonych w subtree i wysyłania ich z powrotem do oryginalnego repozytorium upstream za pomocą git subtree split i push. Ćwiczysz Git Advanced: Monorepo, Submodules & Workflows z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Git Advanced: Monorepo, Submodules & Workflows?
Nie wymagamy żadnego doświadczenia. Git Advanced: Monorepo, Submodules & Workflows w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Wysyłanie zmian z powrotem do upstream za pomocą subtree split”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Git Advanced: Monorepo, Submodules & Workflows?
Tak. Każda lekcja Git Advanced: Monorepo, Submodules & Workflows zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Wprowadzenie do Git Subtree
- Dodawanie i scalanie za pomocą Subtree
- Porównanie Subtree i Submodule
- Wysyłanie zmian z powrotem do upstream za pomocą subtree split