How can I change the language of a repository on GitHub?

Github

Github Problem Overview


GitHub search allows filtering repositories by language. How can I set a repository to a specific language?

Github Solutions


Solution 1 - Github

You can also override certain files

$ cat .gitattributes
*.rb linguist-language=Java

Source

Solution 2 - Github

It is purely deduced from the code content.

As Pedro mentions:

> Please note that we count the total bytes of each language's file (we check the extension) to decide the percentages.
This means that if you see your project reported a JavaScript, but you swear you use Ruby, you probably have a JS lib somewhere that is bigger than your Ruby code

As detailed in "GitHub changes repository to the wrong language", you can add a .gitattributes file in which you can:

  • ignore part of your project (not considered for language detection)

      static/* linguist-vendored
    
  • consider part of your project as documentation:

      docs/* linguist-documentation
    
  • indicate some files with specific extension (for instance *.rb) should be considered a specific language:

      *.rb linguist-language=Java
    

Solution 3 - Github

You can also make some of the files vendor-ed. Just create a .gitattributes file in the main directory. If you want to exclude CSS from the language statistics write into the file something like this. client/stylesheets/* linguist-vendored

This will hide all files in the client/stylesheets/ from the language statistics. In my case these are the .css files.

This solves your problem partly, because hides the most used language and choose the second one to be prime.

Solution 4 - Github

A bit brute-force, but I used this .gitattributes file:

* linguist-vendored
*.js linguist-vendored=false

It says to ignore all files except .js, so JavaScript becomes the only possible language. My project, https://github.com/aim12340/jQuery-Before-Ready, was listed as HTML and this changed it to JavaScript.

Solution 5 - Github

As VonC mentioned in the comments, you can put your libraries under "vendors" or "thirdparty" and the files won't be analysed by linguist, the tool GitHub uses to analyse the language in your code.

# Vendored dependencies
- third[-_]?party/
- 3rd[-_]?party/
- vendors?/
- extern(al)?/

Later, they added more folder names.

Solution 6 - Github

Create .gitattributes file in the root of your folder. Suppose you want the language to be Java, just copy-paste

*.java linguist-detectable=true *.js linguist-detectable=false *.html linguist-detectable=false *.xml linguist-detectable=false

in the .gitattributes file and push the file in the repository. Reload your GitHub page to see the language change.

For reference, use this GitHub repository.

Solution 7 - Github

Rename the name of the code files in your repository with the extension added.

For example:

  • change abc to abc.py for Python
  • abc to abc.java for Java files
  • abc to abc.html for HTML

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionohhoView Question on Stackoverflow
Solution 1 - GithubZomboView Answer on Stackoverflow
Solution 2 - GithubVonCView Answer on Stackoverflow
Solution 3 - GithubKasmetskiView Answer on Stackoverflow
Solution 4 - GithubEamonnMView Answer on Stackoverflow
Solution 5 - GithubNicolas RTTView Answer on Stackoverflow
Solution 6 - GithubSaif SiddiquiView Answer on Stackoverflow
Solution 7 - GithubLakshmana DeepeshView Answer on Stackoverflow