Skip to main content

Feature branches

Every splice syncs with the upstream branch named like your current branch. This walkthrough starts a feature branch in the sandbox, changes one splice on it and pushes, and cleans up once the feature is merged on both sides.

First, splice in pkg-b and bring both splices up to date, as in the main walkthrough:

$ git splice clone https://git.example.com/pkg-b.git vendor/pkg-b >/dev/null && git splice pull --all >/dev/null

A new branchโ€‹

Neither upstream has a feature branch.

$ git switch -c feature
Switched to a new branch 'feature'

Without a feature branch upstream, git-splice compares each splice with upstream's default branch, as a PR from feature would. Right after switching, main has every commit.

$ git splice status
On branch feature

unchanged, no upstream branch vendor/pkg-a
unchanged, no upstream branch vendor/pkg-b

Changing one spliceโ€‹

$ echo "a new option" >>vendor/pkg-b/file.txt && git commit -qam "pkg-b: add an option"
$ git splice status
On branch feature

new, ahead 1 vendor/pkg-b push creates the branch

unchanged, no upstream branch vendor/pkg-a

Without an upstream branch there's no T to compare R with, so diff compares with upstream's main, as a PR would:

$ git splice diff
=== vendor/pkg-b
diff --git a/file.txt b/file.txt
index b041961..b509b97 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1,2 @@
pkg-b: seed
+a new option

push creates feature on pkg-b's upstream only. pkg-a's upstream main has every commit already, so it doesn't get an empty branch. Commits that feature got from main would count too, if upstream's main lacked them: that's how they get upstream when it takes changes only through PRs (scenario).

$ git splice push --all
ok vendor/pkg-a: nothing to push (upstream has no 'feature' branch, and 'main' has every commit)
?? vendor/pkg-b: upstream has no 'feature' branch yet -- this push creates it
ok vendor/pkg-b: pushed 5023101 to feature
$ git splice status
On branch feature

up to date vendor/pkg-b
unchanged, no upstream branch vendor/pkg-a

pull on feature pulls from pkg-b's feature branch. pkg-a's upstream has no feature branch, so there's nothing to pull from it:

$ git splice pull --all
ok vendor/pkg-a fetched
ok vendor/pkg-b fetched
ok vendor/pkg-a: upstream has no 'feature' branch -- nothing to pull
ok vendor/pkg-b: nothing to pull

After the mergeโ€‹

The feature gets merged on both sides: on pkg-b's upstream, which then deletes the branch, and in the monorepo.

$ git -C "$WALKTHROUGH/upstream/pkg-b.git" push -q . feature:main && git -C "$WALKTHROUGH/upstream/pkg-b.git" branch -q -D feature
$ git switch -q main && git merge -q --ff-only feature

Back on main, pull sees that the monorepo already has what upstream merged. Fetching pruned the deleted branch.

$ git splice pull --all
ok vendor/pkg-a fetched
ok vendor/pkg-b fetched (main moved 9b3cb02..5023101)
ok vendor/pkg-a: nothing to pull
ok vendor/pkg-b: nothing to pull
$ git for-each-ref --format='%(refname)' refs/splices/pkg-b/
refs/splices/pkg-b/main
$ git splice status
On branch main

up to date vendor/pkg-a
up to date vendor/pkg-b