Skip to content

Git-Aware Workflows

Claude reads your git state — diffs, logs, branches, status. How to leverage this for context-rich prompts.

Every time you start Claude Code in a git repository, it already knows things about your project that you haven't told it. Which branch you're on, what files you changed, your recent commit history. Not a hidden feature. It's the foundation of some of the most powerful prompts you can write.

Claude Code Sees Your Git State

Claude Code has access to every git command you'd normally run. git status, git diff, git log, git blame, all of it. It reads the output the same way you would, except faster and without the copy-paste dance.

Your current branch. Modified files. Last ten commits. How your branch differs from main. Who last touched a specific line. Claude Code checks all of this without you saying a word.

The real point: you can ask questions that reference this state directly.

# These are all valid prompts inside Claude Code:
"what files have I changed?"
"summarize my recent commits"
"what's different between this branch and main?"

No setup. If you are in a git repo, it works.

Using Diffs as Context

Diffs are absurdly information-dense. Exactly what was added, removed, modified. Basically a cheat sheet for Claude Code.

"review the changes I've made to the authentication module"
"fix the bug introduced in the last commit"
"I changed something in the last 3 commits that broke login. Find it."

That last one is my favorite. You know something broke but you don't want to manually read through three commits worth of diffs squinting at every line. Claude Code runs git diff HEAD~3, reads through everything, and pinpoints the problem. A second pair of eyes that doesn't get tired or distracted by Slack.

Diffs also make great raw material for documentation and commit messages:

"look at all my staged changes and write a detailed commit message"
"summarize everything that changed in this branch for a PR description"

Branch Comparison and History

Branch comparison is where this gets really good. Feature branch and you want the full picture?

"what changed in this branch vs main?"
"show me all the files modified in this feature branch"
"are there any changes in main that I should rebase onto?"

Under the hood it runs git diff main...HEAD or git log main..HEAD --oneline. You don't need to remember those commands. Plain language works.

Git history is just as useful, maybe more so. You can ask Claude Code to trace how code evolved:

"look through ExecutionFactory's git history and summarize how its API came to be"
"who last modified the rate limiter and what did they change?"
"what did we change in the payments module last week?"

That first one comes from the official docs and it is a perfect use case. Instead of running git log --follow and reading through dozens of commits yourself, Claude Code does the archaeology and hands you a clean summary.

Try It: Debug with Git History

Pick a file in your project that recently had a bug fix. Then chain these prompts:

"run git blame on src/api/auth.ts and tell me which recent commit changed the token validation logic"
"show me the full diff of that commit and explain what it changed"
"what was the state of that function before that commit? Was the old version actually correct?"

Each answer gives you context for the next question. You're having a conversation about your git history, and honestly Claude Code is better at reading blame output than most humans.

Status-Based Workflows

git status is valuable context too. Staged, modified, untracked. Claude Code sees all of it.

"I have a bunch of unstaged changes. Group them into logical commits."
"are any of my modified files going to cause merge conflicts with main?"
"I have untracked files. Which ones should be gitignored?"

That first one is a lifesaver. You just finished a long coding session, touched a dozen files, and the last thing you want is one giant "WIP" commit. Claude Code looks at the diffs, groups the changes logically, and helps you create clean, focused commits.

Worth knowing: when you create a PR using gh pr create during a session, that session gets linked to the PR. Resume later with claude --from-pr 42 and it picks up with full context.

Tips for Better Git-Aware Prompts

Be specific. "What changed?" is fine. "What changed in the auth module in the last 5 commits?" is way better. More specificity means better git commands and better answers.

When debugging, point Claude Code at history instead of describing the bug from memory. "Something broke login in the last few days. Check the git history for the auth routes and find what changed." Git doesn't forget things. You do.

New to a codebase? Try "summarize the last 20 commits" or "what are the most actively changed files this month?" Instant orientation.

Combine git with other tools for the real payoff. "Check the git history for changes to the database schema, then read the migration files and tell me if they match." Cross-referencing like this is where Claude Code earns its keep.

TL;DR

  • Claude Code has full access to your git state (diffs, logs, status, blame, branches) with zero setup
  • "What broke in the last 3 commits?" is one of the best debugging prompts you can write
  • Branch comparisons give you instant PR-level context without leaving your terminal
  • Git history prompts turn Claude Code into an archaeologist for your codebase
  • Sessions linked to PRs via gh pr create resume with claude --from-pr, context intact

Mastering Claude Code

Lesson 37 of 70