How to contribute to mathlib #

Here are some tips and tricks to make the process of contributing as smooth as possible.

Once you have code that you'd like to contribute, you should open a PR.

Working on mathlib #

We use git to manage and version control mathlib. The master branch is the "production" version of mathlib. It is essential that everything in the master branch compiles without errors, and there are no sorrys. To ensure this, we only commit changes to master that have passed automated Continuous Integration ("CI") tests, and have been approved by mathlib maintainers.

While you're working on a new contribution to mathlib, you should do this on a different branch. It's okay to do this in your own fork of the mathlib repository, or you can introduce yourself on Zulip and ask for write access to non-master branches of the mathlib repository, you can either make your own thread to introduce yourself, or ask for access in this topic. Please include your GitHub username in your request (and add this username to your Zulip profile, using the personal settings panel). It's polite to prefix the branch name with your username, so it's easier for us to clean up clutter. (Once you're making a pull request, we'll ask you to do so from a branch of the mathlib repository, rather than from your own fork, as CI works better this way.)

Typical workflow:

Making a Pull Request (PR) #

Once you're happy with your local changes, it's time to make a pull request.

Lifecycle of a PR #

We use GitHub "labels" to manage review. (Labels can only be edited by "GitHub collaborators", which is approximately the same as "people who have asked for write access".)

On the main page for a PR, on the right-hand side, there should be a sidebar with panels "reviewers", "assignees", "labels", etc. Click on the "labels" header to add or remove labels from the current project.

The most important labels are "awaiting-review" and "awaiting-author". If your PR builds (has a green checkmark) and you label your PR with "awaiting-review", someone will probably "review" it within a few days (depending on the size of the PR; smaller PRs will get quicker responses). The reviewer will probably leave comments and change the label to "awaiting-author". You should address each comment, clicking the "resolve conversation" button once the problem is resolved. Ideally each problem is resolved with a new commit, but there is no hard rule here. Once all requested changes are implemented, you should change the label back to "awaiting-review" to start the process over again.

After some iteration, a reviewer will "approve" the PR and the "ready-to-merge" label will be automatically applied to the PR. A bot called bors will take it from here. (See here for more detail about bors.) After responding appropriately to bors (if necessary), the PR will get added to the "merge queue". The merge queue gets cleared automatically, but this takes some finite amount of time as it requires building branches of mathlib.

Here are some other frequently-used labels:

Dealing with merge conflicts #

Due to the fact that multiple people work on mathlib in parallel, someone might have introduced a change on master that conflicts with a change that you're proposing on your PR. If it happens with your PR, check this GitHub tutorial on how to resolve merge conflicts by using their online tool.