Git uses the Myers Diff Algorithm. This is a link to the original paper. Here is a Python code and interactive visualization from the Robert Elder's Blog. James Coglan also has a series of articles in his blog about it. Here is a table of contents of the series: