SOP-014: Git Integration
Document Control
| Field | Value |
|---|---|
| SOP ID | SOP-014 |
| Version | 1.0 |
| Status | Active |
| Last Updated | 2024-12 |
Purpose
This SOP covers Git integration features in Cursor, including AI-generated commit messages, merge conflict resolution, and GitHub/GitLab integration.
Scope
- AI commit messages
- Merge conflict resolution
- GitHub integration
- GitLab integration
- Git workflows with Agent
Prerequisites
- Git installed and configured
- Repository initialized
- GitHub/GitLab account (for integrations)
Procedure
Git Integration Overview
| Feature | Description |
|---|---|
| AI Commit Messages | Auto-generate commit messages from staged changes |
| AI Merge Conflict Resolution | Smart resolution understanding both versions |
| GitHub/GitLab Integration | PR reviews, issue tracking, Bugbot automation |
Step 1: AI Commit Messages
Generate Commit Message:
- Stage your changes:
git add . - Open Source Control panel:
Cmd+Shift+G/Ctrl+Shift+G - Click the sparkle icon (✨) in commit message box
- AI generates message based on changes
- Edit if needed, then commit
Keyboard Shortcut: From Source Control panel, focus commit input and use the generate button.
Example:
| Staged Changes | Generated Message |
|---|---|
+ src/auth.ts (new) | Add JWT authentication and update API endpoints |
~ src/api.ts (modified) | - Implement JWT token generation and validation |
| - Add authentication middleware to API routes | |
| - Update error handling for auth failures |
Step 2: AI Merge Conflict Resolution
When you have merge conflicts:
- Cursor detects conflict markers in files
- Click "Resolve with AI" or use Agent
- AI understands both versions and your codebase
- Proposes resolution maintaining functionality
Using Agent:
"Help me resolve the merge conflicts in @src/api.ts.
The main branch added pagination while my branch added filtering.
I need both features to work together."Step 3: GitHub Integration
Setup:
- Open Command Palette:
Cmd+Shift+P - Search "GitHub: Sign In"
- Authorize Cursor with your GitHub account
Features Available:
- View and manage PRs
- Create PRs from Cursor
- View issues
- Bugbot for automated reviews
Step 4: GitLab Integration
Setup:
- Open Cursor Settings
- Navigate to Integrations → GitLab
- Enter your GitLab instance URL
- Authorize access
Step 5: Git Commands with Agent
Ask Agent to perform Git operations:
Examples:
"Show me the changes made in the last 5 commits"
"Create a new branch called feature/user-auth and switch to it"
"Review the changes on this branch compared to main"
"Commit these changes with an appropriate message"
"Push my changes to origin"Git Writes Approval
By default, Agent asks before running Git write operations (commit, push, etc.). Configure in Settings → Agents → Auto-Run.
Bugbot for PR Reviews
Bugbot automatically reviews PRs on GitHub/GitLab.
Setup:
- Install Bugbot from repository settings
- Configure rules in
.cursor/bugbot.md - Bugbot comments on new PRs
Example Bugbot Rule:
markdown
# Bugbot Rules
## Database Migrations
- Check for missing down migrations
- Verify index additions for foreign keys
- Flag destructive changes
## Security
- No hardcoded secrets
- Validate input on all endpoints
- Check for SQL injection patternsCommon Git Workflows
Create Feature Branch
1. Ask Agent: "Create a branch for adding user profile feature"
2. Agent: git checkout -b feature/user-profile
3. Make changes with AI assistance
4. Ask Agent: "Commit these changes"
5. Ask Agent: "Push and create a PR"Review Branch Changes
1. Ask Agent: "What changes have been made on this branch?"
2. Agent runs: git log main..HEAD, git diff main
3. Agent summarizes all changes
4. Ask follow-up questions about specific commitsRevert Changes
1. Ask Agent: "Revert the last commit but keep the changes"
2. Agent: git reset --soft HEAD~1
3. Or: "Completely undo the last commit"
4. Agent: git reset --hard HEAD~1Terminal Settings for Git
Configure Git operations in sandbox:
| Setting | Description |
|---|---|
| Allow Git Writes | Let Agent commit/push in sandbox |
| Network Access | Required for push/pull operations |
Navigate to: Settings → Cursor Settings → Agents
Verification Checklist
- [ ] AI commit message generation works
- [ ] Can sign in to GitHub/GitLab
- [ ] Agent can run git status, diff, log
- [ ] Merge conflict resolution works
- [ ] Git write operations follow approval settings
- [ ] Bugbot configured (if using)
Troubleshooting
| Issue | Solution |
|---|---|
| AI commit message empty | Stage changes first |
| GitHub not connecting | Re-authorize in settings |
| Git commands failing | Check Git is installed and configured |
| Push permission denied | Enable network access in sandbox |
| Merge conflicts not detected | Refresh file or run git status |