A branch is a safe try
You will learn
How a try on a branch is thrown away or merged, and why main is untouched until you choose.
A branch is a copy of your line of work where you can try something, and the main line stays as it was until you decide. In branch.t27 main holds 10 and an agent's try turns it into 99 on its own branch. If the try is bad you delete the branch and main still holds 10. If it is good you merge it and main holds 99. While you try there are 2 lines of work, main and the try; after either ending there is 1. Ask an agent for a risky change on a branch, not on main.
Try it
In the widget, compare the two endings in the table and say which one changes main; then in the spec frame plant the bug MAIN_AFTER_DISCARD = 99 and see which tests turn red.
Two endings of one try on a branch: thrown away, the main line stays as it was; merged, the main line takes the change. Lesson 8 of the course Vibecoding from zero with t27.
specs/vibecoding/branch.t27
// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/branch.t27 -- lesson "A branch is a safe try" of the course "Vibecoding from zero with t27"
; A branch is a copy of your line of work where you can try something. If the try is bad, delete
; the branch and the main line is exactly as it was. If it is good, merge it in. Here the main
; line is one number and a try changes it to another.
; ASCII only, English only.
module vibecoding_branch;
; The main line before the try, and what the agent's try turned it into on its own branch.
pub const MAIN_BEFORE : u8 = 10;
pub const TRY_VALUE : u8 = 99;
; The try went wrong and was thrown away: the main line is untouched.
pub const MAIN_AFTER_DISCARD : u8 = 10;
; The try went well and was merged: the main line takes its value.
pub const MAIN_AFTER_MERGE : u8 = 99;
; Lines of work alive while you try (main and the try), then after the try is deleted.
pub const BRANCHES_WHILE_TRYING : u8 = 2;
pub const BRANCHES_AFTER_DELETE : u8 = 1;
test a_thrown_away_try_leaves_main_alone {
assert MAIN_AFTER_DISCARD == MAIN_BEFORE;
}
test a_merged_try_changes_main {
assert MAIN_AFTER_MERGE == TRY_VALUE;
assert MAIN_AFTER_MERGE != MAIN_BEFORE;
}
test deleting_the_try_leaves_only_main {
assert BRANCHES_WHILE_TRYING - 1 == BRANCHES_AFTER_DELETE;
}
; Negative control: plant the bug "the discarded try leaked into main" (MAIN_AFTER_DISCARD = 99)
; and the first test turns red; with the line as written it stays green.
test negative_control_a_discarded_try_is_not_the_try {
assert MAIN_AFTER_DISCARD != TRY_VALUE;
}
All lessons
Module 1 · What vibecoding is
You describe, an agent writes, you run it and check. What a program is, and five myths put to a test.
Module 2 · Your desk
An editor with an agent beside it, ten terminal commands, and reading an error message.
Module 3 · Save points with git
A commit is a save point, a branch is a safe try, and a key is a pair of which one stays private.
Module 4 · Prompting
The parts of a prompt, an example in place of an adjective, and one small step at a time.
Module 5 · The working loop
Four phases from idea to ship, the loop of ask, run, read and fix, and what to do when it is stuck.
Module 6 · A test as the judge
A test says yes or no, a planted bug shows the test works, and a diff is read before it is accepted.
Module 7 · The parts of an agent
What an agent answers with, what it can do with tools, and what it keeps between messages.
Module 8 · A first bot
A bot is a message loop, a bot comes from a spec, and a secret stays out of the repository and the prompt.
Module 9 · Your own project
A spec for your own idea, one thing measured after it runs, and an honest plan for the next month.