PTENES
Skip to content
MODULE 4.4

🤖 Git with AI — Version Control

Semantic commits, smart staging, diff review, merge conflicts, branching, and secret security. All with Claude Code in your Git workflow.

6
Topics
~40
Minutes
Git
Prerequisite
Practical
Type
Progress:0%0 of 6
1

Semantic commits with Claude

When you ask Claude to commit, it analyzes the diff, identifies the type of change (feat, fix, refactor, docs, etc.), and generates a message in the conventional commits. This keeps the history readable and makes automatic changelogs easier.

commit-semantico.sh
# Peca ao Claude para commitar as mudancas atuais
# Ele vai:
# 1. Rodar git status e git diff
# 2. Analisar o que mudou
# 3. Gerar mensagem semantica
# 4. Commitar com a mensagem

# Prompt: "commita essas mudancas com mensagem semantica"
# Output: git commit -m "feat(auth): add JWT refresh token rotation"

In one sentence: Claude analyzes the diff and automatically generates semantic commits (feat/fix/refactor).

2

Smart staging

Claude prefers adding specific files to staging (git add arquivo.ts) instead of git add -A. It groups logically related files into a single commit, creating atomic commits where each one represents a single coherent change. This is critical: if you need to revert, you revert one logical unit, not a blob of mixed changes.

In one sentence: Claude groups related files into atomic commits and never blindly uses git add -A.

3

Automated diff review

Before committing, ask Claude: "review the current diff". It runs git diff --staged, analyzes the changes, and reports potential bugs, style inconsistencies, broken logic, and missing imports. It’s like having an instant code reviewer before every commit.

diff-review.sh
# Pedir review do diff antes de commitar
git diff --staged | head -200
# Prompt: "analisa esse diff e me diz se tem algum problema"

In one sentence: Claude reviews the diff before commit and catches bugs before they enter the history.

4

Merge conflicts

Merge conflicts are version control’s nightmare. With Claude, you can ask: "resolve the merge conflicts in file X". It understands the semantic context on both sides; it doesn’t resolve things mechanically (accept one side or the other), but integrates the intents of both branches. For complex conflicts, it may ask which behavior you prefer.

In one sentence: Claude resolves merge conflicts semantically, integrating the intent of both branches.

5

Branching strategy

With AI in your workflow, short-lived branches work better. The pattern: create a branch for each feature/fix, let Claude work on it, and merge quickly. Long-lived branches accumulate divergence and make the agent's work harder. Prefer feat/add-auth that lasts 1-2 days to develop that accumulates over weeks.

In one sentence: short, focused branches are an AI agent's best friend.

6

.gitignore and security

Claude Code has built-in safety rules: it never commit .env files, credentials, or keys without explicit notice. But you should also keep your .gitignore up to date. Ask Claude to audit: "check whether there's any secret that isn't in .gitignore". Prevention is better than remedying a credential leak.

Never commit

.env, *.pem, credentials.json, *.key, node_modules/, .claude/ (which contains temporary worktrees). If it leaked, rotate the keys immediately.

In one sentence: Updated .gitignore + an attentive Claude = zero secret leaks.

🧾 Module Summary

✓
Semantic commits — Claude automatically generates feat/fix/refactor.
✓
Atomic staging — related files in the same commit.
✓
Pre-commit diff review — catch bugs before they enter the history.
✓
Secret security — .gitignore + Claude = zero leaks.

Next module:

4.5 — Pull Requests and Code Review: Automated PRs with the gh CLI.