Eshaan Sharma
Eshaan Sharma

Reputation: 95

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

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.

Upvotes: 8

Views: 4926

Answers (1)

Chris
Chris

Reputation: 136910

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.

Upvotes: 18

Related Questions