How can .gitattributes be used to get Github to display the correct primary language for a repo?
Asked Answered
H

1

8

I wrote a program in Python and used Bootstrap for its frontend.

When I upload the directory on GitHub it shows that the project is 90% JavaScript and only 7.5% Python. I understand that this is happening because of the JS directory in the Bootstrap folder.

I need to display Python as the primary project language for the repo.

I did a little bit of research and learnt that adding the file .gitattributes to your project is a solution, but I have no idea what to add in that file to get Github ignore JavaScript when assessing the primary language of the project.

I checked out the official .gitattributes manual page but couldn't find a direct solution to this issue.

Here's what the repo looks like

Repo screenshot

Link to Github repo

Edit: All the CSS and JS files are in the static/ folder, so I added a .gitattributes file to the repo and added static/* linguist-vendored in the first line, however the repo still shows JS as 90% of the language.

Hake answered 18/4, 2018 at 11:42 Comment(6)
github.com/github/linguist/issues/2989 - is this of any help?Reducer
Or this: https://mcmap.net/q/1323692/-why-changing-github-repository-language-not-working/1758363Reducer
Hi, thanks for the response! All the css and js files are in the static folder and even after adding static/* linguist-vendored as the first line in .gitignore, the repo still shows JS as 90% of the project language. I took help from this page hackernoon.com/… I'm going through your links too.Hake
Your last line is *.js linguist-vendored=false so all JavaScript files will be counted in statistics. I think you want *.js linguist-vendored. And you can remove the two first lines.Pompeii
Possible duplicate of How to change the language of a repository on GitHub?Pompeii
@Pompeii omg that worked INSTANTLY. Thank you so much!Hake
M
18

The official gitattributes documentation won't say anything about this since it's a GitHub-specific feature. Git itself doesn't do language statistics.

GitHub uses a tool called Linguist for language statistics, and Linguist allows you to specify paths it should ignore using a custom linguist-vendored attribute:

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

Note that the effects of this change can take some time to appear:

When you push changes to a repository on GitHub.com, a low priority background job is enqueued to analyze your repository as explained above. The results of this analysis are cached for the lifetime of your repository and are only updated when the repository is updated. As this analysis is performed by a low priority background job, it can take a while, particularly during busy periods, for your language statistics bar to reflect your changes.

Give GitHub a day or two to catch up after you've changed your .gitattributes.

Milkandwater answered 18/4, 2018 at 12:13 Comment(5)
Thanks for your response Chris. I added the last 2 lines from the above codeblock into my .gitattributes file and it still does't change anything. This is that the file looks like atm github.com/sharmaeshaan/Stats4R/blob/master/.gitattributesHake
@EshaanSharma, please see the note I just added to my answer. Also note that the examples I gave are straight from Linguist's documentation; you probably don't literally need special-vendored-path/* linguist-vendored in your repo.Milkandwater
Got it. Thanks for your help!Hake
Hey @Chris, the solution was to add just one line -- *.js linguist-vendored in .gitattributes and the changes reflected instantly. The repo is now showing Python as the primary language. Thanks anyway for your inputs.Hake
@EshaanSharma, are you sure the background job I mentioned didn't just finish running?Milkandwater

© 2022 - 2024 — McMap. All rights reserved.