Git Workflow with AI
Write better commits, generate changelogs, and resolve merge conflicts using AI
AI in Your Git Workflow
Git is where development work gets captured, reviewed, and shipped. AI can improve every stage: writing descriptive commit messages, summarizing changes for PRs, generating changelogs, and resolving tricky merge conflicts — all without leaving your terminal.
Writing Better Commit Messages
Vague commits like fix stuff or update make history useless. Use AI to generate structured, meaningful messages from your staged diff.
# Stage your changes, then ask Claude Code: git add -p # stage specific hunks git diff --staged | claude "Write a conventional commit message for these changes. Format: type(scope): description Types: feat, fix, refactor, docs, test, chore" # Example output: # feat(auth): add JWT refresh token rotation # - Tokens now auto-rotate on each request # - Old tokens invalidated after rotation # - Added 15-minute expiry to refresh tokens # Or use Copilot CLI (gh copilot): gh copilot suggest "git commit message for adding rate limiting to API"
type(scope): messageTypes: feat, fix, docs, style, refactor, perf, test, chore, ci
Generating PR Descriptions
A good PR description saves reviewers time. Generate one from your commit log:
# Get commits since branching from main: git log main..HEAD --oneline > commits.txt # Ask AI to write the PR description: claude "Based on these commits, write a GitHub PR description with: - Summary (2-3 sentences) - What changed (bullet points) - How to test - Any breaking changes $(cat commits.txt)" # Or paste the full diff for more detail: git diff main..HEAD | claude "Write a comprehensive PR description for this diff"
The result is a structured description that reviewers appreciate and that creates a permanent record of why the change was made.
Resolving Merge Conflicts with AI
Merge conflicts are stressful because you need to understand both sides of the change. AI can explain what each side did and suggest the correct resolution.
# When git shows conflict markers: <<<<<<< HEAD const timeout = 5000; // your change ======= const timeout = 30000; // their change >>>>>>> feature/slow-network
# Paste the conflicted file into Claude Code: claude "This file has merge conflicts. Explain what each side changed and suggest the correct resolution, preserving both teams' intentions." # Or in Copilot Chat: # /fix — it detects conflict markers and proposes resolutions
Always review AI's resolution. It may not know which timeout value is correct for your use case — that business context is yours to provide.
Generating Changelogs
Turn your git log into a human-readable changelog for releases:
# Get commits between two tags / releases: git log v1.2.0..v1.3.0 --oneline > release-commits.txt # Ask AI to generate a changelog: claude "Generate a CHANGELOG.md section for version 1.3.0 from these git commits. Group into: New Features, Bug Fixes, Breaking Changes, and Internal Improvements. $(cat release-commits.txt)" # Example output: ## [1.3.0] - 2025-10-15 ### New Features - Added JWT refresh token rotation (#auth) ### Bug Fixes - Fixed race condition in checkout flow ### Breaking Changes - Auth API endpoint moved from /auth to /api/auth
Interactive Git Help with Claude Code
Use Claude Code as a git expert when you're unsure of the right command:
# Ask for git commands you can't remember: claude "How do I squash my last 5 commits into one before merging?" claude "What's the git command to find which commit introduced a bug in auth.ts?" claude "How do I undo my last commit but keep the changes staged?" # Git bisect workflow with AI: claude "Walk me through using git bisect to find when the login bug was introduced. The bug exists in HEAD but not in the v1.0 tag." # Stash management: claude "I have changes in 3 files. I need to switch branches. What's the safest way to stash only the changes in src/auth/ and keep the rest?"
Automating Repetitive Git Tasks
Use AI to write git hooks and scripts that enforce quality automatically:
# Ask AI to write a commit-msg hook: claude "Write a Git commit-msg hook that enforces conventional commit format and rejects commits without a type prefix like feat:, fix:, docs: etc." # Ask AI to write a pre-push hook: claude "Write a pre-push hook that runs npm test and blocks push if tests fail" # The hooks go in .git/hooks/ (or use husky for team sharing): npm install --save-dev husky npx husky add .husky/commit-msg 'npx commitlint --edit $1'
git diff --staged | claude "Write a conventional commit message for this". Use the AI-generated message for your actual commit. Compare it to what you would have written yourself.git diff --staged | claude "Write a conventional commit message"
type(scope): description — feat, fix, refactor, docs, test, chore
git log main..HEAD --oneline | claude "Write a PR description"
Paste conflicted file, ask AI to explain both sides and suggest resolution
git log v1.0..v2.0 --oneline | claude "Generate CHANGELOG section"
claude "How do I squash my last 5 commits?" — use Claude as a git expert
Ask AI to write commit-msg or pre-push hooks, deploy via husky