Enviando alterações de volta à origem com divisão de subtree
Aprenda a extrair alterações feitas dentro de uma subtree e enviá-las de volta ao repositório de origem usando git subtree split e push.
Enviando alterações de volta à origem com divisão de subtree é uma aula grátis de Git Advanced: Monorepo, Submodules & Workflows no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Git Advanced: Monorepo, Submodules & Workflows, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Git Advanced: Monorepo, Submodules & Workflows inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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.
Perguntas Frequentes
A aula “Enviando alterações de volta à origem com divisão de subtree” é grátis?
Sim — o texto completo de “Enviando alterações de volta à origem com divisão de subtree” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Git Advanced: Monorepo, Submodules & Workflows, atualize para CoddyKit PRO. O curso de Git Advanced: Monorepo, Submodules & Workflows inclui 4 aulas no total.
O que vou aprender em “Enviando alterações de volta à origem com divisão de subtree”?
Aprenda a extrair alterações feitas dentro de uma subtree e enviá-las de volta ao repositório de origem usando git subtree split e push. Você pratica Git Advanced: Monorepo, Submodules & Workflows com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Git Advanced: Monorepo, Submodules & Workflows?
Nenhuma experiência prévia é necessária. Git Advanced: Monorepo, Submodules & Workflows no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Enviando alterações de volta à origem com divisão de subtree”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Git Advanced: Monorepo, Submodules & Workflows?
Sim. Cada aula de Git Advanced: Monorepo, Submodules & Workflows inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Introdução ao Git Subtree
- Adicionando e Mesclando com Subtree
- Comparação entre Subtree e Submódulo
- Enviando alterações de volta à origem com divisão de subtree