Force GitHub syntax highlighting language on source files

githubsyntax highlighting

I have some C++ source files in a GitHub repository which have an extension of .C and are using C syntax highlighting, which I don't want.

How can I set GitHub to apply C++ syntax highlighting to these files?

Is there a method to how GitHub identifies the source language for syntax highlighting purposes?

It looks like it uses only the file extension, but is there a way to force a particular language?

Best Answer

I asked support@github.com; this is their reply:

We use Pygments (http://pygments.org/) to do syntax highlighting and determine which lexer to use based on each file's extension. So unfortunately, it doesn't look like there's a way to get C++ highlighting without renaming the files from *.c -> *.cpp and *.h -> *.hpp.

You can do this without losing git history of a file by using the git mv command.