Lesson 1 · Git workflow in the age of agents

A branch is a sticky note, not a folder

One mental model, then one full trip around GitHub flow: branch, commit, push, pull request, merge, sync. About 25 minutes.

Today’s win: you’ll merge your first pull request into a real GitHub repo, and you’ll know what every command did to your branches.

The one idea

So far you’ve used Git as a row of save points on one line. That line is called main. The idea that unlocks everything else is how small a branch really is: Quote: Chacon & Straub, Pro Git §3.1, “Branches in a Nutshell”. The book adds that a branch is “a simple file that contains the 40 character SHA-1 checksum of the commit it points to.”

“A branch in Git is simply a lightweight movable pointer to one of these commits.”

A branch is a label stuck on a commit. When you commit, Git moves the label you are on forward to the new commit. How does Git know which label you’re on? Through one more pointer, HEAD: “a pointer to the local branch you’re currently on.” The HEAD definition is from the same Pro Git §3.1. In diagrams, HEAD → marks the branch you have checked out.

“Making a branch copies my project.” It doesn’t. Creating a branch writes one tiny file holding a commit ID. That’s why branches are cheap enough to make one per task, or one per agent.

Watch the labels move

Predict before you reveal: you’re on add-greeting and you make one commit. Which label moves, and where does main end up?

Reveal the answer

Only the branch HEAD points to moves. main stays exactly where it was. Your work is now off to the side, and main doesn’t change until you decide to merge.

This is the core safety habit for working with AI agents. Every task, whether yours or an agent’s, gets its own branch, so main moves only when someone merges a reviewed pull request. Claude Code works this way too: claude --worktree feature-auth runs the agent on a new branch named worktree-feature-auth, away from your checkout. Branch-per-change: GitHub Docs, “GitHub flow”. Agent branches: Claude Code docs, “Run parallel sessions with worktrees”. Worktrees get their own lesson later.

The loop you’ll use forever

GitHub’s official workflow is six steps. You’ll do all six below. Steps paraphrased from GitHub Docs, “GitHub flow”, which recommends “a separate branch for each set of unrelated changes” so reviews stay focused and one delayed change doesn’t hold up the others.

  1. Branch off main, with a short descriptive name like add-greeting.
  2. Commit small, self-contained changes, then push the branch to GitHub.
  3. Open a pull request (PR): a request to merge your branch, with a summary of what changed and why.
  4. Address review by pushing more commits to the same branch. The PR updates itself.
  5. Merge once it’s approved and the checks pass.
  6. Delete the branch. The PR and its history stay on GitHub.

Do it: your first trip around the loop

Build the sandbox in ~/Work/git-sandbox, not inside a folder that is already a Git repo: a repo nested inside another causes confusion. Run every command yourself. Typing them is part of the practice.

  1. Create the sandbox repo, locally and on GitHub
    cd ~/Work && mkdir git-sandbox && cd git-sandbox
    git init
    echo "# git-sandbox" > README.md
    git add README.md
    git commit -m "Initial commit"
    gh repo create git-sandbox --private --source=. --push

    The last line creates a private repo on GitHub, adds it as a remote called origin, and pushes main to it. Flags from gh repo create --help (gh 2.58): --source uses an existing local repo, --push pushes its commits. See the gh manual.

  2. Make a branch and see where HEAD is
    git switch -c add-greeting   # create the label AND move HEAD to it
    git branch

    The * next to add-greeting is HEAD. You’re now in the middle diagram above: two labels on the same commit.

  3. Commit on the branch, then look at the graph
    echo "Hello from a branch" > greeting.txt
    git add greeting.txt
    git commit -m "Add greeting file"
    git log --oneline --graph --all

    Find the line with (HEAD -> add-greeting) and the line below it with main. That’s the “reveal” diagram, printed by Git. --all shows every branch, not only the one you’re on.

  4. Push the branch to GitHub
    git push -u origin add-greeting

    This sends the new commit and the add-greeting label to origin. The -u flag links your local branch to the remote one, so later a plain git push knows where to go. Lesson 2 covers remotes properly.

  5. Open the pull request and read its diff
    gh pr create --fill
    gh pr view --web

    --fill uses your commit message as the PR’s title and body. In the browser, open the Files changed tab. That’s the diff: green lines were added, red lines were removed. Reading this tab carefully is your most important job once agents write the code. --fill: “Use commit info for title and body.” gh manual, gh pr create.

  6. Merge it and delete the branch
    gh pr merge --merge --delete-branch

    --merge keeps your commit and records the merge with a merge commit (GitHub’s default method). --delete-branch removes the branch both locally and on GitHub. Squash and rebase merges come in a later lesson. Merge methods: GitHub Docs, “About merge methods on GitHub”.

  7. Bring local main up to date, then verify
    git switch main
    git pull
    git log --oneline --graph --all
    ls

    The merge happened on GitHub, so your local main was behind until git pull brought it up to date. You should see a merge commit at the top, greeting.txt in ls, and no add-greeting branch left.

Close the feedback loop: paste the output of the last git log --oneline --graph --all into Claude Code. I’ll check it with you and explain any line that looks surprising.

Recall it

No scrolling up. Retrieving from memory is what makes this stick. Effortful recall builds long-term retention better than rereading. Try this quiz again in two or three days.

Go deeper

Primary source: Pro Git §3.1, “Branches in a Nutshell” (about 10 minutes, with the diagrams this lesson is based on). Then skim GitHub flow, which you just did by hand.

Optional extra practice: the first three levels of the “Introduction Sequence” on Learn Git Branching, a visual sandbox.

Cheat sheet: GitHub flow commands, for when you need a command quickly.

Something unclear, or a command printed something unexpected? Ask me in Claude Code. I’m your teacher for this course. Questions like “why did git pull say fast-forward?” are exactly what I’m here for.

Related ideas