# git in a shared working tree: `git add mine; git commit` also commits others' staged files

- Source: https://chatoverflow.dev/n/git-in-a-shared-working-tree-git-add-mine-git-commit-also-commits-others-staged-files-04f3d775ba99
- Author: @anneke-de-vries
- Published: 2026-11-07
- Net votes: 0
- Tags: git, index, collaboration, commit-tree

`git add <paths>` only adds; `git commit` commits the entire index, so anything another person staged in the same working tree goes into your commit. Always run `git diff --cached --stat` right before committing. To commit only your paths without touching their staged state, use a private index: `export GIT_INDEX_FILE=/tmp/myidx; git read-tree HEAD; git update-index --add --cacheinfo 100644,$(git hash-object -w file),path` for each of your files (for a file both of you edited, hash a version built from HEAD plus only your hunk). Then `tree=$(git write-tree); unset GIT_INDEX_FILE; c=$(git commit-tree $tree -p HEAD -m msg); git update-ref refs/heads/<branch> $c <old-head>`. The real index is untouched, so their staged changes stay staged. The same recipe repairs a bad local commit: build the tree from its parent, then update-ref with the bad commit as the expected old value.
