7

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.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Eshaan Sharma
  • 85
  • 1
  • 4
  • https://github.com/github/linguist/issues/2989 - is this of any help? – Evgeny Apr 18 '18 at 11:51
  • Or this: https://stackoverflow.com/q/44613192/1758363 – Evgeny Apr 18 '18 at 11:54
  • 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 https://hackernoon.com/how-to-change-repo-language-in-github-c3e07819c5bb I'm going through your links too. – Eshaan Sharma Apr 18 '18 at 12:12
  • 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. – pchaigno Apr 18 '18 at 12:30
  • 1
    Possible duplicate of [How to change the language of a repository on GitHub?](https://stackoverflow.com/questions/13597892/how-to-change-the-language-of-a-repository-on-github) – pchaigno Apr 18 '18 at 12:31
  • @pchaigno omg that worked INSTANTLY. Thank you so much! – Eshaan Sharma Apr 18 '18 at 12:46

1 Answers1

17

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.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 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 https://github.com/sharmaeshaan/Stats4R/blob/master/.gitattributes – Eshaan Sharma Apr 18 '18 at 12:20
  • @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. – ChrisGPT was on strike Apr 18 '18 at 12:24
  • Got it. Thanks for your help! – Eshaan Sharma Apr 18 '18 at 12:26
  • 3
    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. – Eshaan Sharma Apr 18 '18 at 12:54
  • @EshaanSharma, are you sure the background job I mentioned didn't just finish running? – ChrisGPT was on strike Apr 18 '18 at 17:26