Git tutorial
This tutorial creates four temporary GitHub repositories with fixed names, and it runs four agent workflows in them. After each turn of the agent, it tells you what to check. The steps for pull requests (PRs) first create the PRs. A later step merges them, and then the cleanup deletes the temporary repositories.
You learn these review shapes and checks:
- ordinary git branch PR
- ordinary git multi-commit PR
- stacked PRs with plain git for dependent slices
- physical git worktrees for independent parallel slices
- tag classification and ast-grep dependency checks before code edits
Every step uses plain git and gh.
Pull request command map
The tutorial creates its PRs with these commands:
- Step 1:
gh pr create --base main --head tutorial/plain - Step 2:
gh pr create --base main --head tutorial/multi - Step 3:
gh pr create --base main --head tutorial/stack-base, thengh pr create --base tutorial/stack-base --head tutorial/stack-child - Step 4:
gh pr create --base main --head tutorial/worktree-aandgh pr create --base main --head tutorial/worktree-b
A stack is a chain of branches, where each branch starts from the branch below it. Open the PRs
of a stack from the bottom branch up. Give each PR the branch below it as its base, with
gh pr create --base <parent-branch>. Then each PR shows only the change of its own branch.
What the tutorial does
The agent creates these GitHub repositories under your GitHub account, and it deletes them later:
agent-gest-git-tutorial-plain
agent-gest-git-tutorial-multi
agent-gest-git-tutorial-stack
agent-gest-git-tutorial-worktreesDo not use these names for anything valuable. Before the agent starts, the prompts below tell it
to delete each repository that has one of these names. The cleanup deletes them again with
gh repo delete --yes.
Before you start, make sure of these things:
gh auth status -h github.comsucceeds.- Your GitHub auth has the
repoanddelete_reposcopes. git2.38 or later,gh,gestandjustare installed.- You agree that the agent creates and deletes the four temporary repositories above.
Step 0: Setup and cleanup contract
What this step teaches:
The agent uses fixed names for the repositories, and it cleans up before and after the tutorial. It also tells you where it wrote the logs.
Ask the agent:
Run the Git tutorial setup.
Use my GitHub account from `gh api user -q .login`.
Use exactly these temporary private repo names:
- agent-gest-git-tutorial-plain
- agent-gest-git-tutorial-multi
- agent-gest-git-tutorial-stack
- agent-gest-git-tutorial-worktrees
Before starting, delete any existing GitHub repos with those names using
`gh repo delete <owner>/<name> --yes`, ignoring "not found" errors.
Create a local tutorial root at `/tmp/agent-gest-git-tutorial`.
Create `/tmp/agent-gest-git-tutorial/logs`.
For each following step, write a command log in that logs directory. After the
PR-opening steps finish, merge the PRs in Step 6. After the merge step, delete
the four GitHub repos unless I explicitly ask to keep them.After the agent finishes, check:
test -d /tmp/agent-gest-git-tutorial/logsThe agent reports your GitHub owner and the exact directory of the logs.
Step 1: Ordinary git branch PR
What this step teaches:
Use ordinary git for one simple review branch.
Repository:
agent-gest-git-tutorial-plainAsk the agent:
Run tutorial step 1: ordinary git branch PR.
Create private GitHub repo `agent-gest-git-tutorial-plain`.
Clone or initialize it under `/tmp/agent-gest-git-tutorial/plain`.
Create `main` with README.md containing `plain tutorial base`.
Push `main`.
Create branch `tutorial/plain` with ordinary git.
Add `plain.txt` containing `plain branch change`.
Commit with message `test: add plain branch change`.
Push the branch.
Open a PR:
```bash
gh pr create \
--repo "$(gh api user -q .login)/agent-gest-git-tutorial-plain" \
--base main \
--head tutorial/plain \
--title 'test: plain git branch flow' \
--body 'Tutorial plain git branch flow.'
```
Write all commands and key outputs to
`/tmp/agent-gest-git-tutorial/logs/01-plain-git-branch.log`.After the agent finishes, check:
gh pr view tutorial/plain \
--repo "$(gh api user -q .login)/agent-gest-git-tutorial-plain" \
--json state,baseRefName,headRefName,titleExpected:
state: OPEN
baseRefName: main
headRefName: tutorial/plain
title: test: plain git branch flowCommands that the agent should use:
git checkout -b tutorial/plain, or another ordinary git command that creates the branchgit commitgit pushgh pr create
Step 2: Ordinary git multi-commit PR
What this step teaches:
Use ordinary git when one review branch needs more than one commit.
Repository:
agent-gest-git-tutorial-multiAsk the agent:
Run tutorial step 2: ordinary git multi-commit PR.
Create private GitHub repo `agent-gest-git-tutorial-multi`.
Clone or initialize it under `/tmp/agent-gest-git-tutorial/multi`.
Create `main` with README.md containing `multi tutorial base`.
Push `main`.
Create branch `tutorial/multi` with ordinary git.
Add `session.txt` containing `session edit one`.
Commit with message `test: add first session edit`.
Append `session edit two` to `session.txt`.
Commit with message `test: add second session edit`.
Push the branch.
Open a PR:
```bash
gh pr create \
--repo "$(gh api user -q .login)/agent-gest-git-tutorial-multi" \
--base main \
--head tutorial/multi \
--title 'test: multi commit git branch flow' \
--body 'Tutorial multi-commit git branch flow.'
```
Write all commands and key outputs to
`/tmp/agent-gest-git-tutorial/logs/02-multi-commit-git-branch.log`.After the agent finishes, check:
owner="$(gh api user -q .login)"
gh pr view tutorial/multi \
--repo "$owner/agent-gest-git-tutorial-multi" \
--json state,baseRefName,headRefName,title,commitsExpected:
state: OPEN
baseRefName: main
headRefName: tutorial/multi
title: test: multi commit git branch flow
commits: two commits on the PR branchStep 3: Stacked PRs with plain git
What this step teaches:
Use a stack when you have several large slices that depend on each other, and each slice needs its own review. Each branch of the stack starts from the branch below it, and each PR targets the branch below it.
Repository:
agent-gest-git-tutorial-stackAsk the agent:
Run tutorial step 3: stacked PRs with plain git.
Create private GitHub repo `agent-gest-git-tutorial-stack`.
Clone or initialize it under `/tmp/agent-gest-git-tutorial/stack`.
Create `main` with README.md containing `stack tutorial base`.
Push `main`.
Create branch `tutorial/stack-base` from `main`.
Add `stack.txt` containing `stack base`.
Commit with message `test: stack base flow`.
Create branch `tutorial/stack-child` from `tutorial/stack-base`.
Append `stack child` to `stack.txt`.
Commit with message `test: stack child flow`.
Change the lower branch once, to show how the stack moves together:
switch to `tutorial/stack-base`, add `base-note.txt` containing `base note`,
and commit with message `test: add base note`. Then switch to
`tutorial/stack-child` and run:
```bash
git rebase --update-refs --onto tutorial/stack-base 'tutorial/stack-base@{1}'
```
`tutorial/stack-base@{1}` is the lower branch before the new commit.
Push both branches.
Open the two PRs from the bottom branch up:
```bash
owner="$(gh api user -q .login)"
gh pr create \
--repo "$owner/agent-gest-git-tutorial-stack" \
--base main \
--head tutorial/stack-base \
--title 'test: stack base flow' \
--body 'Tutorial stack base flow.'
gh pr create \
--repo "$owner/agent-gest-git-tutorial-stack" \
--base tutorial/stack-base \
--head tutorial/stack-child \
--title 'test: stack child flow' \
--body 'Tutorial stack child flow.'
```
Write all commands and key outputs to
`/tmp/agent-gest-git-tutorial/logs/03-stacked-prs.log`.After the agent finishes, check:
owner="$(gh api user -q .login)"
gh pr list \
--repo "$owner/agent-gest-git-tutorial-stack" \
--state open \
--json title,baseRefName,headRefNameExpected:
PR: test: stack base flow
baseRefName: main
headRefName: tutorial/stack-base
PR: test: stack child flow
baseRefName: tutorial/stack-base
headRefName: tutorial/stack-childCommands that the agent should use:
git switch -c tutorial/stack-base maingit switch -c tutorial/stack-child tutorial/stack-basegit commitgit rebase --update-refs --onto tutorial/stack-base 'tutorial/stack-base@{1}', after a change to the lower branchgit pushgh pr create --base mainfor the bottom PR, andgh pr create --base tutorial/stack-basefor the child PR
The --update-refs option needs git 2.38 or later. With it, a rebase of the top branch also
moves each branch below it that the rebase passes. The step does not use physical git worktrees.
Step 4: Physical git worktrees
What this step teaches:
Use physical git worktrees for independent slices that run in parallel. A physical worktree is a separate folder with its own checkout of a branch. Give each agent that writes its own worktree, so that two agents never write in one folder.
Repository:
agent-gest-git-tutorial-worktreesAsk the agent:
Run tutorial step 4: physical git worktrees.
Create private GitHub repo `agent-gest-git-tutorial-worktrees`.
Clone or initialize it under `/tmp/agent-gest-git-tutorial/worktrees`.
Create `main` with README.md containing `worktree tutorial base`.
Push `main`.
Create two physical git worktrees:
- `/tmp/agent-gest-git-tutorial/worktree-a` on branch `tutorial/worktree-a`
- `/tmp/agent-gest-git-tutorial/worktree-b` on branch `tutorial/worktree-b`
In worktree A, add `worktree-a.txt` containing `worktree a isolated change`,
commit with message `test: add worktree a change`, push the branch, and open a
PR:
```bash
gh pr create \
--repo "$(gh api user -q .login)/agent-gest-git-tutorial-worktrees" \
--base main \
--head tutorial/worktree-a \
--title 'test: worktree a flow' \
--body 'Tutorial physical worktree A flow.'
```
In worktree B, add `worktree-b.txt` containing `worktree b isolated change`,
commit with message `test: add worktree b change`, push the branch, and open a
PR:
```bash
gh pr create \
--repo "$(gh api user -q .login)/agent-gest-git-tutorial-worktrees" \
--base main \
--head tutorial/worktree-b \
--title 'test: worktree b flow' \
--body 'Tutorial physical worktree B flow.'
```
Remove both physical worktrees after the PRs are open.
Write all commands and key outputs to
`/tmp/agent-gest-git-tutorial/logs/04-physical-worktrees.log`.After the agent finishes, check:
owner="$(gh api user -q .login)"
gh pr list \
--repo "$owner/agent-gest-git-tutorial-worktrees" \
--state open \
--json title,baseRefName,headRefNameExpected:
PR: test: worktree a flow
baseRefName: main
headRefName: tutorial/worktree-a
PR: test: worktree b flow
baseRefName: main
headRefName: tutorial/worktree-bCommands that the agent should use:
git worktree add ...- ordinary
git commitinside each physical worktree gh pr create
What the agent should not do:
- run two agents that write in one folder
Step 6: Merge the tutorial PRs
What this step teaches:
A durable checkpoint does not end when the PRs are open. Review and accept each PR before you merge it. Then merge the PRs before the cleanup. The merge before the cleanup tests the deletion of branches, the state of the PRs and the order of the stacked PRs.
Ask the agent:
Run tutorial step 6: accept and merge tutorial PRs.
Use my GitHub account from `gh api user -q .login`.
Before merging, record each PR number with `gh pr view <branch> --json number`.
For each PR, run the PR acceptance checkpoint first:
- inspect `gh pr view <number> --json number,url,state,isDraft,title,body,headRefName,baseRefName,mergeable,reviewDecision,commits,files,statusCheckRollup,latestReviews`
- inspect `gh pr diff <number> --patch`
- inspect `gh pr checks <number>`, treating "no checks reported" as an
explicit state to report, not as a silent pass
- report findings first
- report PR state, checks, branch/base, mergeability, and the exact merge
recommendation
- stop and ask before merging if there are findings, mergeability is not clean,
or the PR target/branch shape is not the expected tutorial shape
After explicit merge authorization, merge these PRs with `gh pr merge <number> --merge`, and
verify each PR state is `MERGED` by PR number:
- repo `agent-gest-git-tutorial-plain`, PR branch `tutorial/plain`
- repo `agent-gest-git-tutorial-multi`, PR branch `tutorial/multi`
- repo `agent-gest-git-tutorial-worktrees`, PR branch `tutorial/worktree-a`
- repo `agent-gest-git-tutorial-worktrees`, PR branch `tutorial/worktree-b`
For repo `agent-gest-git-tutorial-stack`, merge in this order:
1. merge PR branch `tutorial/stack-child` into `tutorial/stack-base`
2. merge PR branch `tutorial/stack-base` into `main`
Write all commands and key outputs to
`/tmp/agent-gest-git-tutorial/logs/06-merge-prs.log`.After the agent finishes, check:
owner="$(gh api user -q .login)"
gh pr list \
--repo "$owner/agent-gest-git-tutorial-plain" \
--state merged \
--search "head:tutorial/plain" \
--json state,baseRefName,headRefName,title
gh pr list \
--repo "$owner/agent-gest-git-tutorial-multi" \
--state merged \
--search "head:tutorial/multi" \
--json state,baseRefName,headRefName,title
gh pr list \
--repo "$owner/agent-gest-git-tutorial-stack" \
--state merged \
--json title,baseRefName,headRefName
gh pr list \
--repo "$owner/agent-gest-git-tutorial-worktrees" \
--state merged \
--json title,baseRefName,headRefNameExpected:
plain PR: state MERGED, baseRefName main, headRefName tutorial/plain
multi PR: state MERGED, baseRefName main, headRefName tutorial/multi
stack child PR: state MERGED, baseRefName tutorial/stack-base
stack base PR: state MERGED, baseRefName main
worktree A PR: state MERGED, baseRefName main
worktree B PR: state MERGED, baseRefName mainCommands that the agent should use:
gh pr view <branch> --json number, before it deletes the branches of the PRsgh pr view <number> --json ...,gh pr diff <number> --patchandgh pr checks <number>, as the PR acceptance checkpoint before each mergegh pr merge <number> --mergegh pr vieworgh pr list --state merged
What the agent should not do:
- delete the temporary repositories before it verifies that each PR has the state
MERGED - delete the stacked branches before it merges the child PR and the base PR of the stack
Step 7: Cleanup
Ask the agent:
Run tutorial cleanup.
Delete these GitHub repositories if they exist:
- agent-gest-git-tutorial-plain
- agent-gest-git-tutorial-multi
- agent-gest-git-tutorial-stack
- agent-gest-git-tutorial-worktrees
Use `gh repo delete <owner>/<repo> --yes`.
Remove `/tmp/agent-gest-git-tutorial/worktree-a` and
`/tmp/agent-gest-git-tutorial/worktree-b` if they still exist.
Keep `/tmp/agent-gest-git-tutorial/logs` unless I ask you to remove logs.After the cleanup, check one repo:
owner="$(gh api user -q .login)"
gh repo view "$owner/agent-gest-git-tutorial-plain"Expected:
repository not foundAutomated regression labs
The scripts in this repo are regression checks. They are not the beginner tutorial:
just tag-dependency-live-lab
just language-profile-labsRead this tutorial first. Use the labs when you want to verify the repository of reusable skills.
For this tutorial, main is the selected integration target. In an existing project, use the
declared target in every step. The declared target can be a persistent experiment branch.
Clean up only a temporary topic branch that you verified as merged, and that no stack and no
worktree depends on. Keep the persistent branches. For the details, read
the integration contract.