I uploaded a smart contract written in Solidity to github but it is not syntax highlighted. Instead it looks like a regular text file. I would like syntax highlighting to be shown on Github. How do I achieve that?

  • I think this is a very valid question and relevant to this forum. I think it should be reopened. – Thorkil Værge Apr 27 '18 at 13:19
  • 1
    As of January/2020 this is not needed anymore as github recognizes .sol files automatically – Willian Mitsuda Jan 2 '20 at 2:47

You need to tell github that this file is a Solidity file. Github will not recongnize .sol files automatically at the moment. Add this line to your .gitattributes file:

*.sol linguist-language=Solidity

If you do not have a .gitattributes file you need to create one and place it in the root directory of your git project.

  • That doesn't seem to work anymore. Is there a newer method that works? – schemar Mar 4 '19 at 16:04
  • 1
    @schemar it does work, you may have to wait a while, or push another commit to .sol files for it to take effect. – Adrin Nov 1 '19 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.