GitHub changes repository to the wrong language
Asked Answered
I

14

148

I know this isn't a huge deal, but I like my GitHub to be linguistically diversified. I wrote a project in Swift and when I commit it says it's in Objective-C.

I think it might be because the Parse frameworks are written in Objective-C and it detects that, but is there a way to change the display language on the main repository page?

Ivaivah answered 11/1, 2016 at 3:26 Comment(1)
Possible duplicate of How to change the language of a repository on GitHub?Mcmullen
F
169

I found the simplest thing was to create a file called .gitattributes in the root folder of my repository, and give it these contents:

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

This example tells GitHub/Linguist to ignore all files, and then just look at .js files. My project, https://github.com/aim12340/jQuery-Before-Ready, was listed as HTML because the HTML example files were bigger than the JavaScript files. This file fixes it for me and now it's listed as JavaScript.

Foxglove answered 20/4, 2017 at 13:16 Comment(5)
just create a new .gitattributes file under repo root folder with content above, instant fix !Herd
Maybe a dummy comment, but in case you wonder what to do exactly, 1. Follow the guidance of @Gob00st in his comment, and 2. Replace ".js" by the extension of your main language files.Hinckley
I had a similar problem for my ASP.NET core project. Github thought it was a javascript repo because of the amount of js files under the www folder. Adding .gitattributes file with [webprojectfolder]/wwwroot/* linguist-vendored fixed it. Thank you.Zaccaria
I added the .gitattributes file with the above contents, except that I replaced the *.js with *.arr because those files were misidentified as Pyret. Now the repo is allegedly 100% Pyret and there's no Python left, so it had the opposite effect for me…Noticeable
@Noticeable Try changing the .js to .py if you want it to be shown as Python.Foxglove
V
79

As mentioned in the GitHub help page

GitHub uses the open source Linguist library to determine file languages for syntax highlighting and repository statistics.
Some files are hard to identify, and sometimes projects contain more library and vendor files than their primary code.

So you need to check with github/linguist#troubleshooting in order to fix this situation.

The percentages are calculated based on the bytes of code for each language as reported by the List Languages API.
If the bar is reporting a language that you don't expect:

  • Click on the name of the language in the stats bar to see a list of the files that are identified as that language.
  • If you see files that you didn't write, consider moving the files into one of the paths for vendored code, or use the manual overrides feature to ignore them.
  • If the files are being misclassified, search for open issues to see if anyone else has already reported the issue. Any information you can add, especially links to public repositories, is helpful.
  • If there are no reported issues of this misclassification, open an issue and include a link to the repository or a sample of the code that is being misclassified.

Update February 2017 (one year later):

The article "How to Change Repo Language in GitHub" from Monica Powell

Upon researching how to resolve GitHub misclassifying the language of your projects I found out the solution is as simple as telling GitHub which files to ignore.

While you still want to commit these files to GitHub and therefore can’t use a .gitignore you can tell GitHub’s linguist which files to ignore in a .gitattributes file

static/* linguist-vendored

This one-line file told GitHub to ignore all of my files in my static/ folder which is where CSS and other assets are stored for a Flask app

The "Using .gitattributes" section does illustrate how to mark wrong languages.
For instance:

Checking code you didn't write, such as JavaScript libraries, into your git repo is a common practice, but this often inflates your project's language stats and may even cause your project to be labeled as another language.
By default, Linguist treats all of the paths defined in vendor.yml as vendored and therefore doesn't include them in the language statistics for a repository.

Use the linguist-vendored attribute to vendor or un-vendor paths.

$ cat .gitattributes
special-vendored-path/* linguist-vendored
jquery.js linguist-vendored=false
Vierno answered 11/1, 2016 at 6:9 Comment(2)
Worked for me, although now wondering how this could still work on GitHub if .gitattribute is in .gitignore as GitHub obviously needs the file but I don't really want it in my repo any more…Vocoid
In my case I wanted my GitHub profile's README.md to show up (as it was literally the only file in that repo anyway) so I created the .gitattributes with: *.md liguist-detectable README.md -linguist-documentation details linkShuttlecock
T
41

To make it simple, let me share my steps:

  1. Change directory to your project root folder;

  2. Create a file named .gitattributes using whatever tools of your choice:

     touch .gitattributes
    
  3. Edit the file by following the Linguist library instructions to tell GitHub how to do it, for example:

     vi .gitattributes
    

    Using linguist-vendored can let GitHub know to "skip" detection for this folder and sub-folders:

    src/main/resources/static/* linguist-vendored

    Use the linguist-documentation attribute to mark or unmark paths as documentation:

    project-docs/* linguist-documentation

    OR mark an individual file containing documentation

    documented_code.rb linguist-documentation=true

    This is a bit weird, but you can do also -- to tell GitHub to treat some files with a specific extension (e.g., *.rb) as Java:

    *.rb linguist-language=Java

  4. Git add, commit and then push it to GitHub. The label will be corrected almost immediately.

Toombs answered 12/10, 2016 at 3:6 Comment(1)
Worked for me, I have added below lines to my .gitattributes file *.java linguist-detectable=false *.dart linguist-language=Dart *.dart linguist-detectable=true android/* linguist-vendored build/* linguist-vendoredHint
S
25

Replace your .gitattributes with this, which reclassifies all files as Java.

 *.* linguist-language=Java

linguist

Superego answered 18/2, 2019 at 11:8 Comment(0)
P
20

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 repo. Refresh your GitHub page to see the language change.

Note: So, for the desired language make it true and other's false. It should work fine.

Pinnacle answered 15/8, 2019 at 4:33 Comment(0)
A
5

I had a project that was started in Objective-C and changed to Swift completely (new project, but in the same repository directory). GitHub kept identifying it as Objective-C no matter what I used in file .gitattributes (all solutions in previous answers).

So, if the jig is up, and you're sure all the project is one language - you radically add:

# Direct Swift
*.* linguist-language=Swift

Only that fixed the problem :)

Antiquarian answered 12/12, 2018 at 16:0 Comment(0)
O
5

You can avoid unexpected languages detection (by filename extension, or by project subfolder, etc.) by using the GitHub linguist detectable option in your .gitattributes file:

Only programming languages are included in the language statistics. Languages of a different type (as defined in languages.yml) are not "detectable" causing them not to be included in the language statistics.

Use the linguist-detectable attribute to mark or unmark paths as detectable:

*.kicad_pcb linguist-detectable=true
*.sch linguist-detectable=true
tools/export_bom.py linguist-detectable=false
Odaodab answered 20/2, 2019 at 15:42 Comment(0)
D
2

In the .gitattributes file just tell Linguist not to determine file languages which you don't want.

Example for ignoring JavaScript files:

*.js linguist-vendored
Diahann answered 25/1, 2019 at 11:1 Comment(0)
S
2

The answer is pretty simple:

just add these lines in your project terminal

  1. touch .gitattributes

    After writing this command, the file .gitattributes should be found in project explorer. If this file does not appear, try to show hidden files to find it.

  2. *.* linguist-language=Java

    Change Java with your target language -Swift in your case-

  3. git add .

  4. git commit -m "Change tagged language from Java to Kotlin"

  5. git push

Now after refreshing the GitHub page, you should found the new update.

Suspicion answered 10/2, 2020 at 17:14 Comment(0)
U
2

If you want to change the language of the Laravel repository, then add the following line to your .gitattributes file:

*.blade.php linguist-vendored

GitHub defines Blade files as HTML, but *.html linguist-vendored doesn't work.

Unconsidered answered 2/5, 2020 at 2:52 Comment(0)
B
1

The solution which was provided by the expert EamonnM who answered this question above worked in my project, but there are two significant things.

  1. The language in the beginning of the second line of his code was the language you want instead of the language you dislike. Remember to distinguish it.

  2. It seems that you could not type any space before the *. (For example, I should type *.swift linguist-vendored=false when I want to change my language into Swift.)

Boodle answered 21/7, 2018 at 14:58 Comment(0)
L
1

I have problem with this also. I created .gitattributes in root of my project. I removed .js and .cs, but .html is still there. This is my .gitattributes file:

*.cs linguist-detectable=true
*.js linguist-detectable=false`
*.html linguist-detectable=false
*.xml linguist-detectable=false

When I add * linguist-vendored, I don't see anything on GitHub.

Enter image description here

Answer:

It is still the same. .html is still shown.

Luis answered 13/12, 2019 at 11:54 Comment(1)
I think the "quote" at the end of the second line (after false) breaks the file :)Stooge
C
1
  1. Create file ".gitattributes" in the root folder.

If you want your git to detect only .java files, you can use:

*.java linguist-detectable=true
*.* linguist-detectable=false

The . means every other file should not be detected as language. For those who want more than 2 languages to be detected, they can manipulate this file.

Celestinecelestite answered 11/12, 2021 at 16:33 Comment(1)
This ignores every language, switch the order of the lines.Fantasy
B
0

Create a file named .gitattributes to your project root folder. Adding {file_name} linguist-generated=true can do the trick. In my case,

mvnw.cmd linguist-generated=true
mvnw linguist-generated=true

worked for me.

Boar answered 1/1, 2018 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.