Skip to content

SOP-014: Git Integration

Document Control

FieldValue
SOP IDSOP-014
Version1.0
StatusActive
Last Updated2024-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

FeatureDescription
AI Commit MessagesAuto-generate commit messages from staged changes
AI Merge Conflict ResolutionSmart resolution understanding both versions
GitHub/GitLab IntegrationPR reviews, issue tracking, Bugbot automation

Step 1: AI Commit Messages

Generate Commit Message:

  1. Stage your changes: git add .
  2. Open Source Control panel: Cmd+Shift+G / Ctrl+Shift+G
  3. Click the sparkle icon (✨) in commit message box
  4. AI generates message based on changes
  5. Edit if needed, then commit

Keyboard Shortcut: From Source Control panel, focus commit input and use the generate button.

Example:

Staged ChangesGenerated 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:

  1. Cursor detects conflict markers in files
  2. Click "Resolve with AI" or use Agent
  3. AI understands both versions and your codebase
  4. 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:

  1. Open Command Palette: Cmd+Shift+P
  2. Search "GitHub: Sign In"
  3. 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:

  1. Open Cursor Settings
  2. Navigate to Integrations → GitLab
  3. Enter your GitLab instance URL
  4. 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:

  1. Install Bugbot from repository settings
  2. Configure rules in .cursor/bugbot.md
  3. 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 patterns

Common 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 commits

Revert 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~1

Terminal Settings for Git

Configure Git operations in sandbox:

SettingDescription
Allow Git WritesLet Agent commit/push in sandbox
Network AccessRequired 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

IssueSolution
AI commit message emptyStage changes first
GitHub not connectingRe-authorize in settings
Git commands failingCheck Git is installed and configured
Push permission deniedEnable network access in sandbox
Merge conflicts not detectedRefresh file or run git status

See Also

Built with VitePress | Powered by Claude AI