---
title: Pre-Commit Hooks
description: How to use fastship's git pre-commit hooks
order: 6
---
We provide hooks for the [pre-commit framework](https://pre-commit.com/) to catch and fix uncleaned and unexported notebooks, locally, without having to wait for continuous integration pipelines to run.

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

They are also a good alternative to [opt-in Jupyter pre-save cleaning](git_friendly_jupyter.md#opt-in-jupyter-pre-save-cleaning) if you use a notebook editor other than Jupyter Notebook or JupyterLab (such as VS Code).

## Install pre-commit

...Install pre-commit (check [their latest instructions](https://pre-commit.com/#install) if you have any difficulty with these commands):

#### pip

```sh
pip install pre-commit
```

#### conda

```sh
conda install -c conda-forge pre-commit
```

#### homebrew (macOS)

```sh
brew install pre-commit
```

## Configure pre-commit for your repo

Create a file named `.pre-commit-config.yaml` in the root of your repo, with the following contents:

```yaml
repos:
- repo: https://github.com/AnswerDotAI/fastship
  rev: main
  hooks:
  - id: ship-clean
  - id: ship-export
```

Include only the hook(s) you'd like to run, as well as any other [supported hooks](https://pre-commit.com/hooks.html).

> [!TIP]
> If you expect all collaborators to use pre-commit, add the `.pre-commit-config.yaml` file to your repo. Otherwise, add it to your `.gitignore`.

Install pre-commit hooks into your repo:

```sh
pre-commit install
```

## Make a commit and enjoy pre-commit in action

When you do a `git commit` in a repo that has pre-commit hooks installed, your new workflow will be as follows:

1. pre-commit runs each hook on your *staged* changes (as in, changes that you `git add`ed)
2. If a hook changes files -- for example, if a commited notebook wasn't cleaned -- pre-commit stops the commit, leaving those changes as *unstaged*
3. You can now stage those changes and make any edits required to get pre-commit to pass
4. Redo the `git commit`, and if it succeeds, your commit will be created.

Using it in practice isn't as complicated as it might sound. The best way to figure out if it works for you is to give it a try.

## How to override pre-commit if you get stuck

If you struggle to get pre-commit to pass a commit that you absolutely think is correct, you can [temporarily disable a hook](https://pre-commit.com/#temporarily-disabling-hooks) like this:

```sh
SKIP=hook git commit
```

...where `hook` refers to a valid hook in your configuration, for example, to disable the `ship-export` hook:

```sh
SKIP=ship-export git commit
```

You can also disable pre-commit entirely with the `--no-verify` flag:

```sh
git commit --no-verify
```

Finally, if you decide it's not for you, you can completely remove pre-commit hooks from your repo with:

```sh
pre-commit uninstall
```
