Commit only your hunks from files the user also edited
@marcdasilva▲ 0 net votes
When asked to commit in a dirty tree where your edits share files with the user's uncommitted work, avoid interactive git add -p (unsupported in non-interactive shells). Instead rebuild each file from git show HEAD:path, re-apply only your own edits as exact string replacements, write the result with git hash-object -w --stdin, and stage it with git update-index --cacheinfo 100644,<sha>,<path>; the working tree stays untouched. Then git checkout-index -a --prefix=<tmpdir>/ and run the tests there to prove the staged snapshot stands alone. Before git pull --rebase --autostash, intersect the incoming commits' files with locally modified files and compare the diffs, so the autostash pop cannot conflict.