1

Solution: Create .gitattributes in git folder and paste linguist-languate=text after the file path. Example:

/other_libraries/* linguist-language=text
/linguist_ignore.c linguist-language=text

Note: linguist-vendored=false didn't solve the problem. GitHub still detected marked files as C code.

Problem:

My C++/OpenGL project is compiled using glad.c, and stb_imbage.h is included in mail.cpp file. Both located in root folder which contains .git directory. These two files have to be present in order to compile the project, so I want to keep them.

Issue: GitHub indexes these files and adds them to Language statistic. It is undesirable since it is not the files containing my code.

How do I keep certain files tracked by Git but exclude them from Languages?

I've tried looking for solution in GitHub docs about Linguist and Stack Overflow but without success.

I know how to ignore files using .gitignore. But it's not the solution since ignored files just won't be commited.

CodingTea
  • 15
  • 4
  • 2
    My projects have some languages listed that have only a passing relevance to the bulk of the code. I can't recall, in all the years they were on Github, me caring even a little bit, or figuring out why I should even care in the first place, or what difference does it make. Can you explain what tangible problem this creates? – Sam Varshavchik Dec 13 '22 at 18:14
  • 1
    easiest solution is to live with it. After all, those *are* in your repo, so the statistics are accurate, you just don't like them. – erik258 Dec 13 '22 at 18:15
  • 1
    Those stats aren't about your code, it's about your repository. Not sure you can tell GitHub to ignore them for stats purposes. – tadman Dec 13 '22 at 18:15
  • 1
    One option could be to structure your build system to acquire the files, so that you don't have to commit them. cmake has fetch_content, or you could use Conan or vckpg manifest mode integration. – sweenish Dec 13 '22 at 18:34
  • Try setting `linguist-vendored` attribute; see https://stackoverflow.com/a/70542975/7976758 Found in https://stackoverflow.com/search?q=%5Bgithub-linguist%5D+ignore+files – phd Dec 13 '22 at 19:02
  • Answering to all comments above. I want my repository to reflect **my work** that has been done. Just like other `include` files are not indexed by _Linguist_, the same way I want mentioned libraries not to be indexed as well. – CodingTea Dec 14 '22 at 06:19

1 Answers1

2

GitHub uses Linguist library to generate the language stats.

At https://github.com/github/linguist/blob/master/docs/overrides.md you can read about the ways to override the default behavior using a .gitattributes file. It looks like the following section fits your case the most:

Vendored code

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:

(exmaple follows)

tymtam
  • 31,798
  • 8
  • 86
  • 126