# Using a dev container to configure GitHub language stats

Published: 2025-03-13
Last updated: 2025-03-13

[Development Containers](https://containers.dev/) are awesome because they allow you develop in a sandboxed environment without having to install tools you wouldn't otherwise use outside a given context.

I'm currently working on a repo with a few jupyter notebooks, but also with code in python and rust. Unfortunately, jupyter notebooks contain a lot of generated code (in addition to actual code), and that skews the numbers causing jupyter notebooks to "take over".
![A screenshot of an image that shows &quot;Jupyter Notebook&quot; as 99.7%.](/images/2025/03/jupyter-notebooks-takeover-the-repo.png)Jupyter Notebook taking over my repo.
One way to fix this would be to update `.gitattributes` to override `github-linguist`'s default behavior, commit the change, push the change to the repo's main branch, and check if it worked. 

However, if this does not work in the first try you're going to end up with a polluted commit history. A nicer way to update this would be to run `github-linguist` locally, and test the changes locally before pushing them to GitHub.

## 1. Configure a dev container

Create a new branch:

```sh
git checkout -b fix/github-language-stats
```

Create a Dev container configuration file if you do not already have one:

```sh
mkdir -p .devcontainer
touch .devcontainer/devcontainer.json
```

Edit the `.devcontainer/devcontainer.json` file to use Crazy Max's [`docker-linguist`](https://github.com/crazy-max/docker-linguist) image:

```json
{
  "name": "github-linguist",
  "image": "ghcr.io/crazy-max/linguist:edge"
}
```

Open your project in VS Code and use the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension's "Reopen in Container" command.

## 2. Testing changes locally

Open a command prompt withing VS Code (Ctrl+~) and run `github-linguist` to see the stats for your repo:

```sh
github-linguist
```

Make changes to the `.gitattributes` file as needed, commit the file, and test if it worked by running `github-linguist` again:

```sh
# only commit the .gitattributes file
git add .gitattributes
# consider using git commit --amend for future changes
git commit
# run github-linguist again to see if it worked
github-linguist
```

In my case, I just needed to update `.gitattributes` to include `*.ipynb linguist-documentation`. Here's my before and after:
![](/images/2025/03/github-linguist-stats-local.png)
When you're happy with the results, create a PR and merge it.

## 3. Removing the dev container

Now that we got the `.gitattributes` down, we simply get rid of the changes in the working tree:

```sh
# Remove changes made to .devcontainer/ 
# if you already had an exisiting configuration
git checkout -- .

# Or delete the .devcontainer/ folder if don't need it
rm -rf .devcontainer/
```

It might also be a good idea to get rid of the generated container:

```sh
# Find the container name
docker ps -a --filter "ancestor=ghcr.io/crazy-max/linguist:edge"
# The above command returned:
# CONTAINER ID   NAMES             IMAGE                          
# 235260acf82f   quirky_chatelet   ghcr.io/crazy-max/linguist:edge

# Remove the container
docker rm quirky_chatelet

# Optionally delete the image
docker image rm ghcr.io/crazy-max/linguist:edge
```

## In closing

The whole process took me about 10 minutes:
![](/images/2025/03/github-language-stats-fixed-1.png)
Writing this blog post on the other hand tool close to an hour!

