Commits and pull requests

Claude Code · Essentials · 10 min

Git is where Claude's work becomes permanent and shared, so it is where your review matters most.

Claude Code sees your git state (current branch, uncommitted changes, recent history) and can run git commands for you. You ask in plain language:

  • "what files have I changed?"
  • "commit my changes with a descriptive message"
  • "create a branch called feat/signup-validation"
  • "help me resolve these merge conflicts"

It reads the diff and recent commit messages to match your project's style. By default it adds a short attribution line to commits and PRs saying Claude helped; that can be changed in settings.

For pull requests (a request on GitHub or similar to merge one branch into another, with review), Claude uses the gh GitHub CLI if it is installed and logged in. Installing gh is recommended: it lets Claude open PRs, read review comments and check CI status. "commit with a descriptive message and open a PR" is a complete request.

Good habits:

  • Commit often. Git commits are your real undo history; Claude's checkpoints only cover its own file edits in a session.
  • Review git diff (or /diff) before asking for a commit, especially after long sessions.
  • Keep pushing and deleting branches as actions you approve yourself; in permission rules you can make git push always ask.
  • Start new work on a branch, so a bad session never touches your main branch.

For parallel work, git worktrees (separate folders checked out to different branches of the same repository) let you run several Claude sessions without them editing the same files. A later lesson shows how.

Example

> what have I changed since main?
> create a branch feat/signup-validation and commit these changes
  with a message that explains why, not just what
> open a pull request with a summary and a test plan
  (Claude runs: git switch -c ..., git add ..., git commit ..., git push ...,
   gh pr create --title ... --body ...)
> /diff        # review the working tree yourself at any time

Remember

  • Claude sees branch, changes and history and can run git and gh for you
  • Install and log in to gh so Claude can open PRs and read reviews
  • Commit often and keep pushes as actions you approve

Watch out for

  • Letting a long session run on main with no commits, so one bad change mixes into hours of good ones.

Check yourself

  1. Why is installing the gh CLI recommended for Claude Code?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: code.claude.com/docs/en/common-workflows