0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Lezione

Inviare le modifiche upstream con subtree split

Scopra come estrarre le modifiche apportate all’interno di un subtree e inviarle al repository upstream originale usando git subtree split e push.

Inviare le modifiche upstream con subtree split è una lezione Git Advanced: Monorepo, Submodules & Workflows gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Git Advanced: Monorepo, Submodules & Workflows, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Git Advanced: Monorepo, Submodules & Workflows include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Inviare le modifiche upstream con subtree split» è gratuita?

Sì — il testo completo di «Inviare le modifiche upstream con subtree split» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Git Advanced: Monorepo, Submodules & Workflows, passa a CoddyKit PRO. Il corso Git Advanced: Monorepo, Submodules & Workflows include 4 lezioni in totale.

Cosa imparerò in «Inviare le modifiche upstream con subtree split»?

Scopra come estrarre le modifiche apportate all’interno di un subtree e inviarle al repository upstream originale usando git subtree split e push. Eserciti Git Advanced: Monorepo, Submodules & Workflows con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Git Advanced: Monorepo, Submodules & Workflows?

Non è richiesta alcuna esperienza precedente. Git Advanced: Monorepo, Submodules & Workflows su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Inviare le modifiche upstream con subtree split»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Git Advanced: Monorepo, Submodules & Workflows?

Sì. Ogni lezione Git Advanced: Monorepo, Submodules & Workflows include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione a Git Subtree
  2. Aggiunta e merge con Subtree
  3. Confronto tra Subtree e Submodule
  4. Inviare le modifiche upstream con subtree split
← Torna a Git Advanced: Monorepo, Submodules & Workflows