Parallel & Isolated Git Commits in Monorepos

Agents in the same checkout share their staged changes. If two agents run git add before either commits, the first commit can include both sets of changes.

These commands commit only the named files without including other staged changes.

git add -N new_file.md
git commit --only -m "message" -- tracked_file.md new_file.md

Component 1: git commit --only -- file_path_1

Normal git commit includes all changed files in the index by default. With the --only option you pass the indexed files in the same command to only include them.1

Component 2: git add -N file_path_1

Files must be in the index to be committed. A git add will add untracked files AND their contents. With the option -N or its full option --intent-to-add new files can be added to the index without their contents.2

And that’s it. Add new files without their contents and commit only the files you want in that commit. This allows agents to edit and commit files in parallel without stepping on toes.

This works well only when editing different files. Commits at the same exact moment could still fail, but they are retryable.


  1. --only is implicit when file paths are in the commit arguments. So it can be omitted for brevity. ↩︎

  2. --intent-to-add records the path without adding its contents. ↩︎