Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 474
Eshaan Sharma Avatar asked Apr 18 '18 11:04

Eshaan Sharma


People also ask

How do I change my GitHub repository language?

You cannot change the language of the repository, but you can change the attributes of the github repository. I mean that if you have a project where there are 60% css and 40% javascript you can said to github-linguist, that you want to ignore the css file. this attributes ignore the java files.

How does GitHub detect language?

GitHub uses the open source Linguist library to determine file languages for syntax highlighting and repository statistics. Language statistics will update after you push changes to your default branch.

How do I use .gitattributes file?

gitattributes file allows you to specify the files and paths attributes that should be used by git when performing git actions, such as git commit , etc. In other words git automatically saves the file according to the attributes specified, every time a file is created or saved.

How do I add a language tag to GitHub?

I did find if you go to 'Add topics' on the far left under the 'Code' section, you can add all the languages you used for anyone that might be looking close enough at your project.


1 Answers

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.

like image 148
Chris Avatar answered Oct 18 '22 07:10

Chris