Git & Best Practices
Production Workflows and the Habits That Matter
Video Lesson Coming Soon
A video walkthrough for this module is in production. For now, dive into the written content below.
What You'll Learn
- ✓ Claude Code and git workflows
- ✓ Git workflow examples
- ✓ GitHub Actions with claude-code-action
- ✓ The 60% context rule
- ✓ Short sessions vs long sessions
- ✓ Prompts that get results
- ✓ Always verify: trust-but-check
- ✓ Building your personal workflow
In this module 9 sections
Claude Code and Git
Claude Code understands git natively. It reads your git history, knows which files have changed, understands branch structure, and can perform every common git operation through natural language.
But the key insight is not that Claude Code can run git commands. It is that Claude Code can reason about your changes and produce intelligent commits, branches, and pull requests.
Git Workflow Examples
# Commit with an auto-generated message based on actual changes
> Commit my changes with a descriptive message
# Create a branch, fix a bug, and open a PR — all in one prompt
> Create a branch called fix/auth-timeout, fix the session
timeout bug in auth.ts, and open a PR
# Resolve merge conflicts intelligently
> Resolve the merge conflicts on this branch, keeping our
changes for the API endpoints but accepting theirs for
the database schema
# Write a detailed PR description
> Open a PR for this branch. Describe all the changes,
include a test plan, and mention any breaking changes GitHub Actions with claude-code-action
claude-code-action is a GitHub Action that runs Claude Code in your CI/CD pipeline. You can use it to automate PR reviews, triage issues, fix linting errors, and more.
When someone opens a PR, Claude Code can automatically review the code, suggest improvements, and even push fixes. When someone creates an issue, Claude Code can analyze it, identify the relevant code, and suggest a solution.
GitHub Actions with claude-code-action
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
Review this PR for:
- Security vulnerabilities
- Performance issues
- Missing tests
- Breaking changes
Suggest specific improvements. The 60% Context Rule
When your context window is more than 60% full, Claude Code's output quality starts to degrade. It becomes slower, less accurate, and more likely to repeat itself.
Monitor your context with /cost. When it gets heavy, use /compact to summarize and free space. For unrelated tasks, use /clear to start fresh.
Think of context like RAM — it is finite and needs active management. The best developers manage their context window as carefully as they manage their code.
Short Sessions Beat Long Sessions
The most effective Claude Code pattern is one task per session.
Start Claude Code. Give it a focused task. Get it done. Exit. Start a new session for the next task.
Long sessions with many unrelated tasks cause context confusion. Claude Code starts mixing up details from the bug fix with details from the feature you built afterward. Its suggestions become less precise. Its plans become less coherent.
If a task is genuinely large — like a major refactor — break it into phases. Plan the refactor in one session. Implement phase one in the next. Test in a third. Each session stays focused and clean.
Prompts That Get Results
Not "fix bugs" but "fix the null pointer exception in auth.ts line 42 when the session token is expired." Specificity is the single biggest factor in output quality.
"Look at src/utils/date.ts" is vastly better than "look at the date utilities." File paths give Claude Code exact context.
"Fix this without changing the public API" or "Use only standard library functions" or "Keep backward compatibility with v2." Constraints prevent unwanted changes.
"Run the tests after making changes" or "Make sure the build passes" or "Check that the API response matches this schema." Verification criteria let Claude Code check its own work.
For anything touching 3 or more files, activate Plan Mode first. Let Claude Code investigate and propose before it implements.
Always Verify
Claude Code is powerful but not infallible. Always:
- Review diffs before accepting changes - Run tests after modifications - Check edge cases in generated code - Read the commit message before approving a commit - Test the build before merging a PR
The best workflow is trust-but-verify: let Claude Code do the work, but you own the review. You are the senior developer. Claude Code is the productive junior who needs code review.
Building Your Personal Workflow
/init to create a solid CLAUDE.md /compact when context gets heavy, /clear between unrelated tasks /cost weekly to stay within your plan limits Esc+Esc to rewind when Claude Code takes a wrong turn Key Takeaways
Claude Code handles git natively — commits, branches, PRs, merge conflicts, and code review all work from natural language
The 60% context rule: compact or restart sessions before the context window fills up to maintain output quality
Short, focused sessions with one task each produce better results than long multi-task sessions
The production workflow: Plan Mode for investigation, direct execution for implementation, always review diffs, always run tests