# GitHub

Integrate Better Stack with GitHub to **connect your repositories and enhance error context with `git blame` information**. This integration allows you to quickly pinpoint the exact code changes and authors associated with errors, streamlining your debugging process.

## Setting up the integration

1. Navigate to **Errors** → [Integrations](https://errors.betterstack.com/team/0/integrations/ ";_blank").
2. Find the **GitHub** integration and click **Add**.
3. Follow the authorization steps to connect your GitHub account.
4. Select the GitHub repositories you want to connect to Better Stack.
5. Click **Connect Selected**.
6. Go to **Errors** → [Applications](https://errors.betterstack.com/team/0/applications/ ";_blank"), click **Configure** in the dropdown menu of the application, and select the repository under **Connect repository**.

![GitHub integration settings](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/6a4220c9-d65a-43a3-f50f-b4ddd2f0ac00/md1x =1228x655)

## Git blame

*   **Automatic `git blame` data**: For errors with stack traces, Better Stack automatically fetches `git blame` information from your connected GitHub repositories.
*   **Identify relevant code changes**: See when and what code change introduced an error directly within the error details, including the commit hash and author.
*   **Faster debugging**: Quickly navigate to the relevant line of code in GitHub to inspect the change that might be causing the issue.

![Git blame example](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/a33cab01-00be-4ee5-36f2-0b4df0303d00/lg2x =1189x480)

### Configure git code paths

If the reported path to the source file in your error stack trace doesn't match the path in your repository, you can set up a mapping to correct this. This ensures that `git blame` functionality works correctly.

To configure code path mapping:

1.  Go to **Errors** → [Applications](https://errors.betterstack.com/team/t0/applications/ ";_blank").
2.  Click **Configure** in the dropdown menu of the application.
3.  Navigate to the **Advanced settings** tab.
4.  Under **Configure git code paths**, you'll find two options:
    *   **Stack trace root (prefix to match in stack traces)**: Enter the prefix of the file path as it appears in your stack traces (e.g., `/usr/src/app`).
    *   **Source code root (Replacement prefix for the repository)**: Enter the corresponding relative path to your source code within your repository (e.g., `apps/backend`).

![Code mapping settings](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/a5e2b2cc-68be-43a7-9157-94363fedf200/md1x =1186x312)

## Link pull requests to errors

Paste the error's URL into a pull request to link it to the error. Copy the URL from the error's page in Better Stack, for example `https://errors.betterstack.com/team/t12345/errors/a1b2c3d4?s=67890`, and add it to the pull request description or to a comment on the pull request. Better Stack picks it up when the pull request is opened and whenever the description or a comment is added or edited later.

Once linked, Better Stack:

*   **Shows the pull request on the error's page** with its status: open, merged, or closed.
*   **Comments on the pull request** with the error's type and message, plus links to the error and its application.
*   **Resolves the error when the pull request is merged**, the same way **Resolve in next release** does. This needs the application to report [releases](https://betterstack.com/docs/errors/using-the-product/releases/).

[info]
#### Pull request not linked?
The pull request has to be in the repository connected to the error's application. Check the repository under **Connect repository** in the application's settings.
[/info]

[info]
#### Not seeing the comment on the pull request?
Accept the updated GitHub App permissions. Go to **Errors** → [Integrations](https://errors.betterstack.com/team/0/integrations/ ";_blank"), click **Configure** on the GitHub integration, and follow **Review permissions in GitHub**.
[/info]