🇫🇷 Français

Git Workflows: Commits, PRs, and Checkpoints

Day 6 - Collaborate effectively with Claude Code and Git

By Angelo Lima

Claude Code integrates natively with Git. Today, we’ll explore how to use this integration for professional development workflows.

Automatic Commits with Attribution

Commit Configuration

In .claude/settings.json:

{
  "commit": {
    "templates": "feat: $MESSAGE",
    "trailers": {
      "Co-authored-by": "Claude Code <claude@anthropic.com>"
    }
  }
}

Asking Claude to Commit

> Commit these changes with a descriptive message

Claude will:

  1. Analyze modified files (git diff)
  2. Understand the context of changes
  3. Generate an appropriate commit message
  4. Execute the commit with configured attribution

Example Generated Commit

git commit -m "feat: add rate limiting middleware for auth endpoints

- Implement express-rate-limit for /api/auth/*
- Add configuration for max attempts (5) and window (15min)
- Log blocked requests for security monitoring

Co-authored-by: Claude Code <claude@anthropic.com>"

Conventional Commits

Claude naturally respects Conventional Commits (see my detailed article on this topic):

Prefix Usage
feat: New feature
fix: Bug fix
docs: Documentation
style: Formatting (no code change)
refactor: Refactoring
test: Adding tests
chore: Maintenance

Creating Pull Requests

Asking Claude for a PR

> Create a PR for these changes to the main branch

PR Configuration

{
  "pr": {
    "attribution": "Generated by Claude Code"
  }
}

Complete PR Workflow

# 1. Create a branch
> Create a branch feature/rate-limiting and switch to it

# 2. Implement
> Implement rate limiting on auth endpoints

# 3. Test
> Run the tests: !`npm test 2>&1`

# 4. Commit
> Commit these changes

# 5. Create the PR
> Push and create a PR to main with a summary of changes

Generated PR Structure

## Summary
- Added rate limiting middleware for authentication endpoints
- Configured 5 attempts per 15-minute window
- Added logging for blocked requests

## Changes
- `src/middleware/rateLimit.ts` (new)
- `src/routes/auth.ts` (modified)
- `tests/middleware/rateLimit.test.ts` (new)

## Test plan
- [ ] Unit tests pass
- [ ] Manual testing with curl
- [ ] Load testing completed

---
Generated by Claude Code

Using Checkpoints with Git

Checkpoints were introduced in Day 5 - here we see how they integrate with Git.

The Perfect Duo

Claude Code Checkpoints  →  Quick changes, experimentation
           +
        Git              →  Permanent history, collaboration
# 1. Before a major modification
git add -A && git commit -m "checkpoint: before auth refactoring"

# 2. Work with Claude
> Refactor the authentication system

# 3. If satisfied → final commit
> Commit with a descriptive message

# 4. If not satisfied → options
#    Option A: Claude rewind (Esc Esc)
#    Option B: Git reset
git reset --hard HEAD

Checkpoints vs Git Comparison

Aspect Checkpoints Git
Granularity Each prompt Manual choice
Persistence Session Permanent
Collaboration No Yes
Bash files Not tracked Tracked
Branches No Yes

GitHub Actions with Claude Code

For more advanced CI/CD patterns, see Day 15: CI/CD and Headless Mode.

CI/CD Integration

# .github/workflows/claude-review.yml
name: Claude Code Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: $
          prompt: |
            Review this PR for:
            1. Security vulnerabilities
            2. Performance issues
            3. Code style violations

            Be concise and actionable.
          max_turns: 5

Mention @claude in PRs

With the action configured, you can mention Claude in PR comments:

@claude Can you review the error handling in this file?

Claude will respond with an analysis.

Multi-Claude Workflows

The Concept

Use multiple instances of Claude Code for different tasks:

┌─────────────────┐     ┌─────────────────┐
│ Claude 1        │     │ Claude 2        │
│ (Implementation)│     │ (Review)        │
└────────┬────────┘     └────────┬────────┘
         │                       │
         └───────────┬───────────┘
                     │
              ┌──────▼──────┐
              │   Git Repo   │
              └─────────────┘

Configuration with Git Worktrees

# Create a worktree for review
git worktree add ../project-review feature-branch

# Terminal 1: Implementation
cd project
claude
> Implement feature X

# Terminal 2: Review
cd ../project-review
claude
> Review the changes in src/features/X

Advantages

  • Separate contexts
  • No interference between tasks
  • Cross-verification of code
  • Work parallelization

Git Best Practices with Claude

1. Atomic Commits

> Commit only the files related to rate limiting,
  not the formatting modifications

2. Don’t Commit Secrets

Claude automatically refuses to commit sensitive files:

> Commit all files

Claude: I cannot commit .env as it contains
        secrets. Do you want to exclude it?

3. Descriptive Branches

> Create a branch for this feature

# Claude creates: feature/add-rate-limiting-auth-endpoints
# Not: feature/update or branch1

4. Review Before Push

> Show me the diff of what we're going to push

! git diff origin/main...HEAD

Recovering from a Git Error

Undo the Last Commit (Not Pushed)

> Undo the last commit but keep the files

! git reset --soft HEAD~1

Modify the Last Commit Message

> Change the last commit message to be more descriptive

Recover a Deleted File

> Recover the file src/utils/helpers.ts deleted in the previous commit

! git checkout HEAD~1 -- src/utils/helpers.ts

Daily Workflow Template

# Morning: Start of day
git pull origin main
claude

# 1. See the state
! git status
> Summarize what's left to do on the current feature

# 2. Work in small increments
> Implement [task 1]
> Commit

> Implement [task 2]
> Commit

# 3. Before break/end of day
> Create a draft PR with a progress summary
# OR
> Push the changes to the feature branch

# 4. End of session
/cost
# Add notes to CLAUDE.md if needed

What’s Coming Tomorrow

In Day 7, we’ll see permissions and security in Claude Code: how to protect your sensitive files and control what Claude can do.


This article is part of the “Master Claude Code in 20 Days” series. Day 5: Context and Memory Management

Share: