Version control and team collaboration in Cursor
PLCursor’s agent handles the version-control work around a shared codebase: it drafts commit messages from the staged diff, resolves merge conflicts by reading both branches, writes pull request descriptions, and pre-reviews a teammate’s pull request. Git stays the record of truth, and tests plus git show --remerge-diff prove what the agent changed.
This page is for a developer who has Cursor installed and now works in a repository other people also push to. It is 5 p.m. on a Friday. You merge main into your feature branch before the release and hit a conflict in a file two colleagues changed this week. Their commit messages say “wip” and “fixes”, a teammate’s 600-line pull request has waited two days for review, and you do not have time to read either line by line.
What you get from agent-driven version control in Cursor
Section titled “What you get from agent-driven version control in Cursor”- A safe git baseline, so no agent action can cost you work you have not committed
- A commit-message prompt that follows your team’s convention and describes only what is staged
- A merge-conflict prompt that keeps both sides’ intent, plus two git commands that show exactly what the resolution changed
- A pull request prompt that produces a description a reviewer can act on
- A review prompt for someone else’s pull request that tells you where to look instead of reading every line
- A clear split between what you check, what CI checks, and what Bugbot checks
Team-wide configuration (shared project rules, MCP servers, and skills) is covered in team collaboration in Cursor. This page is about the daily git loop.
Set a safe git baseline before the agent touches history
Section titled “Set a safe git baseline before the agent touches history”Cursor’s agent runs git in its terminal like any other shell command, subject to the run mode you chose (Auto-review, Allowlist or Run Everything; Cursor’s docs, checked 2026-10-12). That makes it fast and also means a wrong git checkout --theirs . runs as readily as a right one. Put the safety net in place first.
-
Start every agent task from a clean tree. Commit or stash what you have;
-ualso stashes untracked files, so nothing new is left behind in the tree:Terminal window git status --shortgit stash push -u -m "before agent task" -
Work on a branch, never on
main. For a task you want isolated from your own editor, use a Cursor worktree, which lets the agent work in a separate git checkout. -
Write the git rules the agent must follow into your project rules (or into
AGENTS.md, which Cursor also reads) so the agent has them in context: never force-push, never rewrite history that is already on the remote, never commit files matching.env*, and stop to ask beforegit reset --hard. -
Keep pushing a human step for now. Let the agent commit locally, and push after you have looked at the checks described below.
Write commit messages from the staged diff
Section titled “Write commit messages from the staged diff”A commit message is the only context a teammate has when they meet your change in a conflict six months from now. The agent writes good ones when you tell it to read only the staged diff and to follow your convention. Without that instruction it tends to describe the whole working tree, including edits you did not stage.
Check the result in five seconds without reading the diff again: run git diff --cached --stat and confirm that every area the message mentions appears in the file list, and nothing in the list is missing from the message.
Resolve merge conflicts without losing either side
Section titled “Resolve merge conflicts without losing either side”Generic “fix these conflicts” requests usually end with the agent picking one side and deleting the markers. The conflict disappears and so does a colleague’s change. The prompt below forces the agent to state each side’s intent first and to stop when the two are incompatible.
-
Start the merge and list the conflicted files:
Terminal window git merge origin/maingit diff --name-only --diff-filter=U -
Give the agent the prompt below with the file list pasted in.
-
When the agent has finished, run the test suite and the type check before you commit. A resolution that compiles but fails a test has dropped behaviour.
-
Commit the merge, then inspect only what the resolution did:
Terminal window git show --remerge-diff HEAD--remerge-diffneeds Git 2.36 or later; check withgit --version. This shows the difference between the conflicted state (with its<<<<<<<markers) and what was committed, so you review the decisions, not the whole files. For a rebase instead of a merge,git range-diff origin/main ORIG_HEAD HEADcompares your commits before and after the rebase.
The “stop and ask” line matters most. It is the difference between a merge you can trust and one where the agent removed a teammate’s fix to make the markers go away.
Open a pull request that a reviewer can act on
Section titled “Open a pull request that a reviewer can act on”A pull request description written from the diff restates the diff. A useful one states the problem, the evidence that the fix works, and where the risk is. To let the agent open the pull request itself, connect the GitHub MCP server (setup in MCP setup for Cursor) or install the GitHub CLI (gh) and sign in once. The first snippet is the remote GitHub MCP server entry for Cursor (use a personal access token); the second authenticates gh:
{ "mcpServers": { "github": { "url": "https://api.githubcopilot.com/mcp/", "headers": { "Authorization": "Bearer YOUR_GITHUB_PAT" } } } }gh auth loginThe Evidence section is what lets a reviewer trust the change without re-running everything. The full contract for agent pull requests, including acceptance results and a risk class, is in the evidence bundle.
Review a teammate’s pull request with the agent
Section titled “Review a teammate’s pull request with the agent”The agent is most useful in review before you read any code: it builds the mental model, points at the risky hunks, and finds missing tests. You still decide whether to approve. Fetch the pull request into a local branch first so the agent works from real files:
git fetch origin pull/123/head:pr-123git diff --stat origin/main...pr-123Read the hunks from step 2 and the missing tests from step 3, then approve or request changes. For a deeper review workflow, including one pass per concern and large refactors, see code review with Cursor.
Where does Bugbot fit in the review loop?
Section titled “Where does Bugbot fit in the review loop?”Bugbot is Cursor’s pull request reviewer: it “reviews pull requests and identifies bugs, security issues, and code quality problems” (cursor.com/docs/bugbot, checked 2026-08-28). It runs on the forge after you push, so it catches what your local checks missed rather than replacing them. Cursor’s help pages, as summarised on 2026-08-28 and not re-verified since, also describe a .cursor/BUGBOT.md file for project-specific review guidance and a bugbot run comment that re-runs a review on demand. Setup, learned rules, and Autofix are covered on the Bugbot page.
To work through Bugbot’s findings in one pass, give the agent the comments rather than retyping them:
Split parallel work across worktrees and cloud agents
Section titled “Split parallel work across worktrees and cloud agents”Two unrelated tasks do not have to wait for each other. A local worktree gives each agent its own checkout on your machine. A cloud agent runs in an isolated VM in the cloud and can be started from the editor or by an Automation (for example, on a new Slack message). Either way, each task ends on its own branch, ready for a pull request, and goes through the same checks. Keep the tasks independent: two agents editing the same module produce the merge conflict from the previous section, and you resolve it later with less context. Worktree setup and parallel runs are covered in checkpoints and branching.
How do you prove the agent’s git work is correct?
Section titled “How do you prove the agent’s git work is correct?”You do not re-read every line. Each artifact has a check that answers one question, and a named person who signs off.
| Artifact | Check | Signs off |
|---|---|---|
| Commit message | git diff --cached --stat matches the areas the message names | Author |
| Merge resolution | Tests and type check pass, then git show --remerge-diff HEAD shows each decision | Author |
| Rebase | git range-diff origin/main ORIG_HEAD HEAD shows no unintended change to your commits | Author |
| Pull request | CI green, and the Evidence section lists the commands run and their results | Author, then reviewer |
| Review of a teammate’s pull request | You read the risk-ranked hunks and the missing-test list | Human reviewer approves |
| Post-push review | Bugbot findings fixed or explained | Author |
When agent-driven git work goes wrong
Section titled “When agent-driven git work goes wrong”- The merge “resolved” by dropping a teammate’s change. Before you commit, run
git merge --abortand start again with the conflict prompt above. After you commit but before you push,git reset --hard ORIG_HEADreturns you to the pre-merge state; this discards the merge commit, so checkgit log -1 ORIG_HEADfirst. - The agent committed something you did not want. Find the last good entry with
git reflog, thengit reset --soft HEAD@{1}(or the SHA from the reflog) to undo the commits and keep the changes staged. - The commit message describes unstaged work. The agent read
git diffinstead ofgit diff --cached. Re-run the commit-message prompt, which names the command explicitly. - A secret or
.envfile reached a commit. If it is not pushed, remove it withgit rm --cached .env, add the pattern to.gitignore, and amend the commit. If it was pushed, rotate the secret first; rewriting history does not remove it from clones and forks. - The agent force-pushed a shared branch. Anyone who still has the old tip can restore it. Ask them to find it in their
git reflogas<old-sha>, then push it back withgit push --force-with-lease=<branch>:<bad-sha> origin <old-sha>:<branch>, where<bad-sha>is the tip the agent pushed. The lease makes the push fail if anyone has pushed since. Then add “never force-push” to your project rules, and protect the branch on the forge. - The agent ignores your git rules. Confirm the rules actually load in a session before you rely on them, and remember that rules apply to Agent only, not to Tab completion, Inline Edit or Bugbot PR reviews (Cursor help, checked 2026-10-12). The check is in team collaboration in Cursor.
Where to go next with Cursor team workflows
Section titled “Where to go next with Cursor team workflows”Did this guide help you?
One tap, no sign-in.
What will you do with it?
How did it read?
What got in the way? Pick any that apply
Your role?
Thanks. I read every answer. Michał Jaskólski
Did this guide help?
One tap each. Close whenever you like.
no sign-in