This was the answer I originally linked to, because I found it to be an exceptional explanation of the inner workings of git. For some reason my submission now just links to the original question.