- Learn
- Development Workflows
- Git Workflows with AI
Learn how to integrate AI into your Git workflow—from writing commits to creating PRs to managing branches.
Git Workflows with AI
AI can significantly improve your Git workflow—from writing better commit messages to creating comprehensive PRs. This lesson covers practical patterns for Git + AI collaboration.
Commit Message Generation
Basic Commit Message
Example prompt:
Generate a commit message for these changes:
[paste git diff]
Follow conventional commits format:
<type>(<scope>): <subject>Types: feat, fix, docs, style, refactor, perf, test, chore
Detailed Commit Message
Example prompt:
Generate a detailed commit message for this change:
[paste diff]
Include:
- Short subject line (50 chars max)
- Blank line
- Detailed body explaining what changed, why, and implementation details
- Reference any related issues
Format:
<type>(<scope>): <subject>
<body>
Refs: #123
Batch Commit Splitting
When you have multiple unrelated changes:
Example prompt:
I have these changes that should be multiple commits:
[paste large diff]
Help me:
- Identify logical groupings of changes
- Suggest which files belong in each commit
- Write a commit message for each group
- Suggest the order to commit them
Ultra-Granular Commits
AI development often produces more changes. Use smaller commits:
Break this feature implementation into atomic commits:
Changes made:
- Added User interface (types.ts)
- Created UserService class (userService.ts)
- Added API routes (routes/users.ts)
- Created UserCard component (components/UserCard.tsx)
- Added tests for UserService (userService.test.ts)
For each commit:
1. What files to include
2. Commit message
3. Order to maintain buildable state
Output:
Commit 1: feat(types): add User interface
Files: types.ts
Commit 2: feat(services): add UserService with CRUD operations
Files: userService.ts
Commit 3: test(services): add UserService tests
Files: userService.test.ts
Commit 4: feat(api): add user API routes
Files: routes/users.ts
Commit 5: feat(components): add UserCard component
Files: components/UserCard.tsx
Pull Request Workflow
PR Description Generation
Example prompt:
Generate a PR description for these changes.
Changes Summary: [brief description of what you built]
Files Changed: [paste diff or list files]
Context:
- Related issue: #123
- Type: feature/bugfix/refactor
- Risk: low/medium/high
Include: Clear title, summary, how to test, screenshots if UI changes, deployment considerations, and checklist.
PR Template
## Summary
[AI-generated summary of changes]
## Changes
- [Change 1]
- [Change 2]
## Type
- [ ] Feature
- [ ] Bug fix
- [ ] Refactor
- [ ] Documentation
## Testing
- [ ] Unit tests added/updated
- [ ] Manual testing completed
### How to Test
1. [Step 1]
2. [Step 2]
## Screenshots
[If applicable]
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Tests pass locally
- [ ] Documentation updated
PR Review Preparation
Before requesting review:
Example prompt:
Review my PR for common issues before I submit:
PR Description: [paste description]
Code Changes: [paste key changes]
Check for:
- Missing test coverage
- Documentation gaps
- Breaking changes not mentioned
- Security considerations
- Performance impacts
Branch Management
Branch Naming
Suggest a branch name for this work:
Task: Implement user password reset functionality
Issue: #456
Type: Feature
Follow pattern: <type>/<issue>-<description>
Output: feature/456-user-password-reset
Branch Strategy Planning
Help me plan branches for this feature:
Feature: Multi-tenant support
Estimated work: 3 weeks
Team: 2 developers
Sub-tasks:
1. Database schema changes
2. Tenant context middleware
3. API modifications
4. Frontend tenant selector
5. Migration scripts
Suggest:
- Branch strategy (feature branch vs multiple branches)
- Merge order
- Integration approach
Handling Merge Conflicts
Conflict Resolution
Help me resolve this merge conflict:
<<<<<<< HEAD
const config = {
apiUrl: '/api/v2',
timeout: 5000,
};
=======
const config = {
apiUrl: '/api/v1',
timeout: 10000,
retries: 3,
};
>>>>>>> feature/update-config
Context:
- HEAD (main): Updated API to v2
- feature/update-config: Added timeout increase and retries
How should I merge these changes?
Conflict Prevention
I'm about to merge a large feature branch.
Main branch changes since branch creation:
[summary of main changes]
My branch changes:
[summary of feature changes]
Potential conflict areas:
[files both touched]
Suggest strategy to minimize conflicts and safe merge approach.
Changelog Generation
Release Changelog
Generate a changelog from these commits:
v1.2.0 commits:
- feat(auth): add OAuth2 support (#123)
- fix(api): handle null user in /profile (#124)
- feat(ui): add dark mode toggle (#125)
- chore(deps): update React to 18.2 (#126)
- fix(auth): session timeout not refreshing (#127)
- docs(readme): update installation instructions (#128)
Format:
## [1.2.0] - YYYY-MM-DD
### Added
### Fixed
### Changed
Semantic Versioning
Based on these changes, what should the next version be?
Current version: 1.2.3
Changes since last release:
- [list changes]
Rules:
- MAJOR: Breaking changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes
Git History Analysis
Understanding Changes
Example prompt:
Explain what this series of commits accomplished:
abc1234 refactor(auth): extract token validation
def5678 feat(auth): add refresh token support
ghi9012 fix(auth): handle expired tokens gracefully
jkl3456 test(auth): add token refresh tests
Summarize:
- The overall goal
- The approach taken
- Current state after these changes
Finding When Bug Was Introduced
Help me use git bisect to find when this bug was introduced.
Bug: [description]
Known good: v1.0.0 (commit abc123)
Known bad: current HEAD
How should I approach this bisect?
What should I test at each step?
Commit Best Practices
Good Commit Messages
Review these commit messages and improve them:
Bad examples:
1. "fixed stuff"
2. "WIP"
3. "updates"
4. "asdfasdf"
Improve each with:
- Clear subject line
- Body if needed
- Following conventional commits
Commit Hygiene
Before committing, verify:
Example prompt:
Review my staged changes for commit hygiene:
[staged changes]
Check for:
- Debug code (console.log, debugger)
- Commented-out code
- TODO comments that should be issues
- Sensitive data (keys, passwords)
- Unrelated changes mixed in
Workflow Integration
Pre-Commit Checks
Generate a pre-commit checklist for our project:
Stack: TypeScript, React, Jest, ESLint, Prettier
Include checks for:
- Code formatting
- Linting
- Type checking
- Test running
- Commit message format
CI/CD Integration
Example prompt:
Our CI pipeline failed with this error:
[CI error output]
Recent commit: [diff of recent changes]
What caused the failure and how do I fix it?
Practice Exercise
Complete this Git workflow exercise:
- Generate commit messages for a mock diff
- Split a large change into atomic commits
- Write a PR description
- Resolve a mock merge conflict
- Generate a changelog from commits
Use proper conventional commit format throughout.
Summary
- Use AI to generate clear, consistent commit messages
- Break large changes into atomic commits
- Generate comprehensive PR descriptions
- Plan branch strategies for complex features
- Analyze and resolve merge conflicts systematically
- Maintain good commit hygiene
Next Steps
Let's explore multi-tool workflows—how to effectively use multiple AI tools together for maximum productivity.