Module 5: Advanced TechniquesLesson 3 of 6
0%
Lesson 3ยท4 min

Git Integration

Use git effectively with Claude Code

Git Integration

Git is your safety net. Use it religiously with Claude Code.

The Golden Rule

Warning

Commit before asking Claude to make big changes. You can always revert!
Terminal
# Before any risky operation
$ git add .
$ git commit -m "Checkpoint before refactoring auth"
# Now let Claude work
> Refactor the authentication to use Supabase Auth
โ–Œ

Branching Strategy

Terminal
# Create a feature branch
$ git checkout -b feature/reviews
# Let Claude build the feature
> Build the review system
# If it works, merge to main
$ git checkout main
$ git merge feature/reviews
# If it's a mess, delete and start over
$ git checkout main
$ git branch -D feature/reviews
โ–Œ

Tip

Feature branches let you experiment without risking your main code.

Reviewing Changes

Terminal
# See what Claude changed
$ git diff
# See all changed files
$ git status
# Review specific file
$ git diff src/components/Reviews.tsx
โ–Œ

Selective Commits

Claude might make multiple changes. Commit selectively:

Terminal
# Add specific files
$ git add src/components/ReviewForm.tsx
$ git commit -m "Add review form component"
$ git add src/lib/reviews.ts
$ git commit -m "Add reviews API functions"
# Or interactive staging
$ git add -p # Review each change
โ–Œ

Aussie Note

Good commit messages are like leaving notes for future-you. "Fix stuff" is useless. "Fix GST calculation for exempt items" is gold! ๐Ÿ’ฐ

Reverting Claude's Mistakes

Terminal
# Undo all uncommitted changes
$ git checkout .
# Revert to a specific commit
$ git reset --hard HEAD~1
# Revert a specific file
$ git checkout HEAD -- src/components/BrokenComponent.tsx
โ–Œ

Having Claude Use Git

Terminal
> Create a new feature branch for the payment integration
Claude: I'll create the branch:
$ git checkout -b feature/payment-integration
Switched to a new branch 'feature/payment-integration'
> After we're done, help me write a good commit message
โ–Œ

PR Workflow

Terminal
# Finish feature on branch
$ git add .
$ git commit -m "Add payment integration with Stripe"
$ git push -u origin feature/payment-integration
# Create PR
$ gh pr create --title "Add payment integration" --body "..."
โ–Œ

Warning

Don't let Claude push directly to main in shared repos. Use PRs for review!

Git Commands Reference

CommandWhat it does
git statusSee changed files
git diffSee exact changes
git add .Stage all changes
git commit -m "msg"Create commit
git checkout .Discard changes
git checkout -b nameCreate branch
git merge branchMerge branch
git log --onelineView history

Key Takeaways

  • Commit before big changes
  • Use feature branches
  • Review diffs before committing
  • Write descriptive commit messages
  • Revert when things go wrong