I was working on an express app with a friend and git auto merged a file after I ran 'git pull'. There were no merge conflicts, but git added duplicate functions to a file after merge. I spent an hour trying to figure our what the problem was before realizing that git had made a mistake while merging.<p>I had never seen such a thing before. How often does something like this happen?
I've never noticed that before, but it's possible that you both had added functions in different places:<p><pre><code> foo() ... ; original
bar() ... ; added by alice
foo() ...
foo() ...
bar() ... ; added by bob
</code></pre>
I haven't tried it, but I could imagine that being seen as separate text additions, and ending up with duplicates if git thinks it needs to merge them:<p><pre><code> bar() ... ; alice
foo() ... ; original
bar() ... ; bob
</code></pre>
You mentioned using `git pull`, which will actually merge things if it thinks it's necessary -- which can lead to tree differences. In practice, I've found it helpful to NEVER USE `git pull`. Rather, I advise using:<p><pre><code> git checkout master
git fetch origin
git merge origin/master --ff-only
</code></pre>
This will ensure that git only does "fast-forward" merges, and does not end up accidentally merging things - and keeps 'origin' as the system-of-record for what's been merged.