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


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


📝 Exercises

  1. Basic (⭐): Use /commit to commit changes, check auto-generated message quality.
  2. Intermediate (⭐⭐): Configure GitHub Actions for auto security review on PRs.
  3. Advanced (⭐⭐⭐): Build complete AI review pipeline (security+quality+coverage) with auto PR comments.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏