The Git Workflow

Use Claude Code with branches and commits so every change is reviewable and reversible.

Because Claude Code edits real files, you want the same safety net you use with any teammate: version control.

A safe pattern

  1. Start from a clean working tree (git status shows nothing to commit).
  2. Create a branch for the task.
  3. Let Claude Code make its edits.
  4. Review the diff, then commit — Claude Code can write the commit message too.

Why branches matter

Working on a branch means you can experiment freely. If you do not like the result, you switch back to your main branch and the change is gone. If you do, you merge it.

Example

Example · bash
# Prepare a clean, isolated space for the change
git status                 # make sure the tree is clean
git checkout -b add-dark-mode

# ...let Claude Code make its edits...

# Review, then commit
git diff                   # read exactly what changed
git add -A
git commit -m "Add dark mode toggle with localStorage persistence"

# Don't like it? Throw it away and go back:
#   git checkout main && git branch -D add-dark-mode

When to use it

  • Have Claude Code work on a dedicated feature branch so its changes can be reviewed as a normal pull request.
  • Ask Claude Code to commit after each logical step so you can git bisect if something breaks.
  • Use git diff to review every file Claude Code changed before merging to main.

More examples

Start from a clean feature branch

Creating a branch first means all of Claude Code's edits are isolated and reviewable via a pull request.

Example · bash
git checkout -b feature/ai-search
claude "Add a semantic search endpoint at /api/search using the existing OpenSearch client"

Review Claude Code's changes with diff

Running a diff before committing lets you catch unwanted changes before they enter version history.

Example · bash
# After Claude Code finishes its task:
git diff --stat          # see which files changed
git diff src/            # review the actual diffs
git add -p               # stage selectively if needed

Ask Claude Code to commit each step

Small atomic commits from Claude Code make it easy to revert a specific step without losing all the work.

Example · bash
claude "Add dark-mode support. After each logical step (context, toggle, styles) commit with a descriptive message so I can review the history."

Discussion

  • Be the first to comment on this lesson.