Project Workflows & Best Practices

Git Workflows for AI Development

4 min read

Integrating AI coding assistants with git requires thoughtful workflows. This lesson covers professional practices for version control with AI-generated code.

The AI-Aware Git Workflow

┌─────────────────────────────────────────────────────────────┐
│                  AI-Aware Git Workflow                      │
└─────────────────────────────────────────────────────────────┘

1. Create feature branch
   └── git checkout -b feature/new-feature

2. Work with AI in iterations
   ├── Generate code with AI
   ├── Review and test
   └── Make atomic commits

3. Squash/organize commits before PR
   └── git rebase -i main

4. Create PR with AI-generated summary
   └── Use AI to summarize changes

5. Code review (human required)
   └── Verify AI output quality

6. Merge with confidence
   └── Squash or merge based on team preference

Commit Strategies

Atomic Commits with AI

Make small, focused commits even when AI generates large changes:

# AI generates a large feature
# Break it into logical commits:

git add src/models/user.ts
git commit -m "feat(models): add User model with validation"

git add src/services/user.ts
git commit -m "feat(services): add UserService for CRUD operations"

git add src/api/users.ts
git commit -m "feat(api): add user API endpoints"

git add src/tests/user.test.ts
git commit -m "test(user): add unit tests for user module"

Commit Messages for AI Code

Include context about AI involvement:

# Format: type(scope): description
# Optional: note AI assistance in body

git commit -m "feat(auth): add JWT authentication

- Implemented with Claude Code assistance
- Added token refresh logic
- Includes rate limiting middleware

Co-authored-by: Claude <noreply@anthropic.com>"

Conventional Commits

Use standard prefixes:

Prefix Use Case
feat: New feature
fix: Bug fix
refactor: Code restructure
test: Adding tests
docs: Documentation
style: Formatting
perf: Performance
chore: Maintenance

Branching Strategies

Feature Branch Workflow

main
├── feature/user-auth    (AI-assisted feature)
│   ├── commit 1: models
│   ├── commit 2: services
│   └── commit 3: tests
└── feature/dashboard    (Another AI feature)
    ├── commit 1: components
    └── commit 2: integration

When to Branch

Create new branch when:
├── Starting any new feature (AI or manual)
├── Doing experimental AI generation
├── Refactoring with AI assistance
└── Before complex AI operations

The Review Checkpoint Pattern

Before significant AI operations, create a checkpoint:

# Before asking AI for major changes
git add -A
git commit -m "checkpoint: before AI refactoring"

# Now work with AI safely
# If something goes wrong:
git reset --hard HEAD~1

# If it works, amend or continue:
git commit --amend -m "refactor: restructure auth module"

Pull Request Best Practices

AI-Generated PR Description

Ask AI to summarize your branch:

Summarize the changes in this branch for a pull request:

Files changed:
- src/models/user.ts (new)
- src/services/user.ts (new)
- src/api/users.ts (new)
- src/tests/user.test.ts (new)

Include:
- Summary (2-3 sentences)
- Changes list
- Testing notes
- Any breaking changes

PR Template for AI Projects

## Summary
[AI-generated summary or manual description]

## Changes
- [ ] Change 1
- [ ] Change 2

## AI Assistance
- [x] Code generated with [Cursor/Claude Code]
- [x] Reviewed for security
- [x] Tested manually
- [x] Unit tests added

## Testing
- Manual testing steps
- Test results

## Screenshots
[If applicable]

Review Checklist

Before requesting review:

□ AI code reviewed by human
□ Tests passing
□ No console.logs or debug code
□ Security considerations addressed
□ Types properly defined
□ Error handling complete
□ Documentation updated

Git Hooks for AI Workflows

Pre-commit Hook

#!/bin/sh
# .git/hooks/pre-commit

# Run type checking
npm run typecheck
if [ $? -ne 0 ]; then
  echo "Type errors found. Please fix before committing."
  exit 1
fi

# Run linter
npm run lint
if [ $? -ne 0 ]; then
  echo "Linting errors found. Please fix before committing."
  exit 1
fi

# Run tests
npm run test:quick
if [ $? -ne 0 ]; then
  echo "Tests failing. Please fix before committing."
  exit 1
fi

echo "Pre-commit checks passed!"

Using Husky + lint-staged

// package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{ts,tsx}": [
      "eslint --fix",
      "prettier --write",
      "jest --bail --findRelatedTests"
    ]
  }
}

Recovery Patterns

Undo AI Changes

# Undo uncommitted changes
git checkout -- .

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Undo last commit (discard changes)
git reset --hard HEAD~1

# Undo specific file
git checkout HEAD~1 -- src/file.ts

Stash During AI Sessions

# Before experimental AI work
git stash push -m "before AI experiment"

# If experiment fails
git stash pop

# If experiment succeeds
git stash drop

Git Bisect for AI Bugs

When an AI change broke something:

git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>

# Git will checkout commits, test each:
npm test
git bisect good  # or bad

# Find the breaking commit
git bisect reset

Collaboration Tips

AI Code Attribution

For transparency in team projects:

# Option 1: Co-author
git commit -m "feat: add feature

Co-authored-by: Claude <noreply@anthropic.com>"

# Option 2: Commit body note
git commit -m "feat: add feature

Implemented with Cursor Composer assistance.
Human reviewed and tested."

Code Review for AI Code

When reviewing AI-generated PRs:

Review Focus:
1. Does it solve the right problem?
2. Edge cases handled?
3. Security implications?
4. Performance acceptable?
5. Maintainable by humans?
6. Tests adequate?

Git Truth: Good git practices are even more important with AI coding. AI can generate code fast, but only disciplined version control keeps it manageable.

In the next lesson, we'll cover team collaboration with AI coding tools. :::

Quiz

Module 6: Project Workflows & Best Practices

Take Quiz