Search code examples
c++gitgithubgithub-linguist

Ignore other library files in GitHub so they do not appear in project's (programming) Languages


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.


Solution

  • 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)