When you want two (or more) agents to work on the same project at the same time without stepping on each other’s changes, Git gives some solution for this. The trick is to use branches and worktrees intelligently.
The Core Idea: Git Merges Branches, Not Folders
Git doesn’t merge folders; it merges commits across branches. This means everyone can share the same project structure, work on the same files, and still stay out of each other’s way as long as they do it on different branches. You don’t need multiple folders inside the repo. You just need a clean branching workflow and discipline. Keep one clean repository structure, then branch out for each agent’s work. Merge when ready.
Set Up the Integration Branch
Think of the integration branch as the central hub where all agents’ work comes together. You create it once from main and use it as the common base for everyone’s branches.
git checkout main
git pull --ff-only
git checkout -b integration
git push -u origin integration
This branch acts as a staging area. Each agent will branch off from integration, do their work, and merge back later. It keeps the main branch clean until you’re ready to deploy or release.
Each Agent Works in Their Own Branch
Now, each agent creates a personal branch to do their work. This keeps the codebase unified but prevents overwriting or merge chaos.
git checkout integration
git pull --ff-only
git checkout -b agent/agent1
# agent edits files as normal
git add -A
git commit -m "Agent1: added new logic"
git push -u origin agent/agent1
Repeat this for agent/agent2 or however many agents you have. Everyone works independently but in the same logical repo structure.
Bringing It All Together: Merging the Agents
Once agents finish their tasks, you merge their work back into integration. This is where Git’s merge magic comes in.
git checkout integration
git pull --ff-only
git merge --no-ff origin/agent/agent1
git merge --no-ff origin/agent/agent2
# resolve any conflicts if they appear
git push
After verifying everything works on integration, you can merge it back into main via a pull request or direct merge. This way, main always stays stable and clean.
True Parallel Work: Separate Working Directories
Even though two agents can work on different branches, they can’t safely work in the same directory at the same moment. The filesystem itself doesn’t allow two processes to edit and commit in the same checkout simultaneously without risk.
To fix that, you have two clean options:
Option A: Separate Clones
Each agent has their own full clone of the repo. It’s simple, safe, and clear.
git clone git@yourrepo.git repo-agent1
git clone git@yourrepo.git repo-agent2
Option B: Git Worktrees
If you don’t want to duplicate the entire repo, use git worktree. It lets you create multiple working directories tied to the same Git data. Each agent gets a dedicated directory without wasting space.
git checkout integration
git worktree add ../repo-agent1 agent/agent1
git worktree add ../repo-agent2 agent/agent2
This way, agents can work truly in parallel in different directories, same underlying repo, no conflicts.
A Git tree can represent multiple agent branches merging into an integration branch before reaching main.
What If You Insist on One Branch?
Technically, you can have everyone work directly on one branch, but it’s a constant fight against merge conflicts and rejected pushes. Git will stop you whenever someone else has pushed since your last pull. You’ll spend time rebasing and fixing conflicts instead of building.
git pull --rebase
# resolve conflicts
git push
It’s possible, but messy. If you ever try it, split work by modules or files so agents don’t edit the same lines. Still, it’s better to use branches for sanity.
Windsurf
All my projects and even this website is build using Windsurf Editor. Windsurf is the most intuitive AI coding experience, built to keep you and your team in flow.
Get in Touch
If you need a developer who delivers fast, reliable, real-world solutions, reach out. Let’s turn your idea or project into something that works.