3

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?

3
  • I think this is a very valid question and relevant to this forum. I think it should be reopened. Apr 27, 2018 at 13:19
  • 2
    As of January/2020 this is not needed anymore as github recognizes .sol files automatically Jan 2, 2020 at 2:47
  • Yup, can confirm that a .gitattributes file is not needed anymore. Oct 8, 2021 at 16:48

1 Answer 1

8

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.

2
  • That doesn't seem to work anymore. Is there a newer method that works?
    – schemar
    Mar 4, 2019 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, 2019 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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