It just sums up file sizes for each extension. Largest one "wins".
We'd like to avoid opening files up and parsing their content, as both would slow down the process... but that might be the only method of resolving conflicts like this one.
Since this is not 100% accurate, that had lead some to add:
I, too, would vote for a simple manual-override switch for the cases where the guess is wrong.
Currently, Github's linguist project is what is used to determine language statistics, as described in this Github blog post (which came out a few months after this question was originally asked).
After some tinkering with linguist I
have noticed this.
For files with a Shebang,
the Shebang is considered when determining the language but seems to be evenly
weighted against other
tokens.
This seems to be a big error because the Shebang should definitively define the
language of the file.
First, know that you can override the language detected for files in your repository using Linguist overrides.
Now, in a nutshell,
Each repository is tagged with the first language from language statistics.
Language statistics count the total size of files for each detected programming or markup language. Vendored, documentation, and generated files are not counted.
The language of each file is detected by the open source project Linguist.
How does Linguist detect languages?
Linguist relies on the following strategies, in order, and returns the language as soon as it found a perfect match (strategy with a single language returned).
Known filename. Some filenames are associated to specific languages (think Makefile).
Look for a shebang. A file with a #!/bin/bash shebang will be classified as Shell.
Known file extension. Languages have a set of extensions associated to them. There are, however, lots of conflicts with this strategy. The conflicting results (think C++, C and Objective-C for .h) are refined by the subsequent strategies.
A set of heuristic rules. They usually rely on regular expressions over the content of files to try and identify the language (e.g., ^[^#]+:- for Prolog).
A naive Bayesian classifier trained on sample files. Last strategy, lowest accuracy. The Bayesian classifier always takes a subset of languages as input; it is not meant to classify among all languages. The best match found by the classifier is returned.
What are unvendored and documentation files?
Linguist considers some files as vendored, meaning they are not included in language statistics. These include third-party libraries such as jQuery and are defined in the vendor.yml configuration file. You can also vendor or unvendor files in your repository using Linguist overrides.
Linguist relies on simple rules to detect generated files, using both the paths and the content of files. Generated files are not counted in language statistics and are not displayed in diffs on github.com.
What about programming and markup languages?
In Linguist, each language is given a type. These types can be found in the main configuration file, languages.yml. Only the programming and markup languages are counted in statistics.