Claude Code: Git Workflow and GitHub Actions
Last updated: 2026-08-31
Claude Code doesn't just write code — it integrates into your Git workflow, from commit conventions to PR reviews, from CI integration to automated fixes.
💡 Tip: Git workflow integration's core is "human-in-the-loop" — Claude Code assists, humans decide. Automation (CI/CD) uses headless mode; daily dev uses interactive mode.
📋 Prerequisites: Chapter 22 - Environment Variables and Dev Configuration
1. What You'll Learn
- Claude Code and Git collaboration
- Commit convention automation
- GitHub Actions integration
- PR auto-review
- Claude Code in CI/CD pipelines
2. Git Workflow Integration
(1) Common Git Integration Commands
| Operation | Command | Description |
|---|---|---|
| Commit changes | /commit |
Auto-generate commit message |
| View changes | /diff |
View current session modifications |
| Undo operation | /undo |
Undo last operation |
▶ Example 1: Claude Code Assisted Git Flow
TEXT
📖 Display only
> Complete user registration feature development
Claude Code: Created files, tests pass ✅
> /commit
Claude Code auto-generates:
feat: add user registration service
- Create registration.service.ts with email/password signup
- Add POST /api/register endpoint
- Add input validation
- Write 6 unit tests (all passing)
Allow commit? [y/n] y
✅ Committed: feat: add user registration service
3. Commit Convention Automation
(1) Conventional Commits Integration
| Change Type | Prefix | Example |
|---|---|---|
| New feature | feat: | feat: add user registration |
| Fix | fix: | fix: token refresh on expiry |
| Refactor | refactor: | refactor: extract validation logic |
| Test | test: | test: add registration tests |
| Docs | docs: | docs: update API documentation |
| Style | style: | style: fix indentation |
| Config | chore: | chore: update dependencies |
4. GitHub Actions Integration
(1) PR Auto-Review
YAML
# .github/workflows/ai-review.yml
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
ai-review:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: AI Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude --headless --output json \
"Review this PR: security, performance, style, test coverage" > review.json
- name: Post Review
run: |
COMMENT=$(jq -r '.result.summary' review.json)
gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
(2) Auto-Fix Lint Issues
YAML
# .github/workflows/auto-fix.yml
name: Auto Fix Lint
on:
push:
branches: [main]
jobs:
auto-fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Fix Lint
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude --headless --allowed-tools Read,Write \
"Run npm run lint, fix all auto-fixable issues"
- name: Commit Fixes
run: |
git config user.name "Claude Code Bot"
git add -A
git diff --staged --quiet || git commit -m "style: auto-fix lint issues"
git push
5. PR Review Practice
(1) Human + AI Dual Review
| Dimension | AI Review | Human Review |
|---|---|---|
| Security vulnerabilities | ✅ Good at | Supplementary |
| Code style | ✅ Good at | Not needed |
| Performance | ✅ General | Critical scenarios |
| Business logic | ❌ Poor at | ✅ Core |
| Architecture design | ❌ Poor at | ✅ Core |
❓ FAQ
Q Can Claude Code auto-merge PRs?
A Technically yes but not recommended. CI Claude Code only reviews and suggests; merge decisions by humans.
Q Who pays for GitHub Actions API costs?
A Uses the API Key in repo Secrets; costs borne by Key owner. Recommend separate CI Key with quota limits.
Q How to avoid CI infinite loops?
A Auto-fix commits shouldn't trigger new workflows. Add
if: github.actor != 'claude-code-bot' in YAML.Q Works with GitLab CI?
A Yes. Claude Code is a CLI tool; any CI environment that can run npm can use it.
📖 Summary
/commitauto-generates Conventional Commits format messages- GitHub Actions uses headless mode for Claude Code integration
- PR auto-review: security, performance, style; Human: business, architecture
- CI Claude Code only suggests, doesn't decide; human-in-the-loop
- Watch for CI infinite loops with auto-fix commits
📝 Exercises
- Basic (⭐): Use
/committo commit changes, check auto-generated message quality. - Intermediate (⭐⭐): Configure GitHub Actions for auto security review on PRs.
- Advanced (⭐⭐⭐): Build complete AI review pipeline (security+quality+coverage) with auto PR comments.