Claude (via Claude Code, or Cowork with shell access) can run git commands directly and handle much of the day-to-day workflow around commits, branches, and PRs.
## What Claude can do
- Write commit messages by reading the actual diff (`git diff`, `git status`, `git log`) rather than guessing — worth asking for this explicitly so the message reflects real changes.
- Create and switch branches, stage files, commit, push.
- Open and review pull requests (via `gh` CLI if installed).
- Resolve merge conflicts by reading both sides of the conflict and proposing a merged version.
- Search history — find when a line was introduced (`git blame`), find a commit that broke something (`git bisect`), or summarize what changed between tags.
- Undo mistakes — revert a commit, reset a branch, recover a dropped stash.
## Good practices
- Ask Claude to run `git status` and `git diff` before committing so you can confirm what's actually being staged.
- For commit messages, ask Claude to base them only on the diff, not on your description of intent — avoids messages that describe what you meant rather than what changed.
- Have Claude show the diff of a fix before committing, especially for anything destructive (rebase, force-push, reset --hard).
- For PRs, ask for a summary of changes plus a "how to test" section — Claude can generate both from the diff and commit history.
## Guardrails worth setting
- Tell Claude not to force-push or rewrite shared/published history without asking first.
- Tell Claude not to commit directly to main/master if your workflow uses feature branches.
- For anything irreversible (deleting branches, hard resets, `git clean -fd`), ask Claude to show you what will be affected before running it.
## Useful patterns
- "Show me the diff, then write a commit message" — review before commit.
- "What changed between v1.2 and v1.3?" — changelog generation from `git log`.
- "Find the commit that introduced this bug" — bisect-style investigation.
- "Resolve these merge conflicts, explain each choice" — conflict resolution with reasoning, not silent overwrites.