> ## Documentation Index
> Fetch the complete documentation index at: https://docs.amnify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connecting GitHub

To sync Terraform templates from your repository, you need to connect a **GitHub repository** to Amnify using a personal access token.

<Info>
  GitHub integrations are used only by the [Deploy](/cspm-deploy/concepts/overview) module for template synchronization. They do not participate in security scanning.
</Info>

***

## Prerequisites

Before you begin, make sure you have:

* A GitHub account with access to the repository containing your Terraform templates
* The repository follows the [Amnify template structure](/cspm-deploy/guides/using-templates#repository-directory-structure)
* The following values ready:
  * **Repository** — in `owner/repo` format (e.g., `my-org/infra-templates`)
  * **Access Token** — a GitHub personal access token with read access to the repository

***

## Choosing a Token Type

GitHub offers two types of personal access tokens:

| Type                           | Prefix           | Best for                                                       |
| ------------------------------ | ---------------- | -------------------------------------------------------------- |
| **Fine-grained (recommended)** | `github_pat_...` | Scoping access to a single repository with minimal permissions |
| **Classic**                    | `ghp_...`        | Quick setup when you're comfortable granting broader access    |

**We recommend fine-grained tokens** because they let you restrict access to the specific repository that contains your templates — nothing else in your GitHub account is exposed.

***

## Method 1: Fine-Grained Token (Recommended)

### Step 1: Create the Token

1. Go to **GitHub → Settings → Developer settings → Personal access tokens → Fine-grained tokens**
   * Direct link: [github.com/settings/tokens?type=beta](https://github.com/settings/tokens?type=beta)
2. Click **Generate new token**
3. Fill in:
   * **Token name** — e.g., `Amnify Template Sync`
   * **Expiration** — choose an appropriate expiration (e.g., 90 days, or custom)
   * **Resource owner** — select the organization or account that owns the repository
4. Under **Repository access**, select **Only select repositories** and pick the repository that contains your templates
5. Under **Permissions → Repository permissions**, grant:
   * **Contents** → **Read-only**
   * **Metadata** → **Read-only** (automatically selected)
6. Click **Generate token**
7. Copy the token immediately — it starts with `github_pat_` and won't be shown again

<Tip>
  Fine-grained tokens can require organization approval. If your organization has an approval policy, an organization admin will need to approve the token before it becomes active. Check with your GitHub organization admin if your token shows a "pending" status.
</Tip>

### Step 2: Add the Integration in Amnify

1. Navigate to **Integrations** and click **Create integration**
2. Select **GitHub** as the provider
3. Fill in:
   * **Display Name** (optional) — a friendly label (e.g., "Infra Templates Repo")
   * **Repository** — in `owner/repo` format (e.g., `my-org/infra-templates`)
   * **Branch** (optional) — the branch to sync from; defaults to `main` if not provided
   * **Access Token** — paste the `github_pat_...` token
4. Click **Create**

***

## Method 2: Classic Token

Use this if fine-grained tokens are not available in your organization or you prefer a simpler setup.

### Step 1: Create the Token

1. Go to **GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)**
   * Direct link: [github.com/settings/tokens](https://github.com/settings/tokens)
2. Click **Generate new token (classic)**
3. Fill in:
   * **Note** — e.g., `Amnify Template Sync`
   * **Expiration** — choose an appropriate expiration
4. Under **Select scopes**, check:
   * **`repo`** (Full control of private repositories) — required for reading private repository contents
5. Click **Generate token**
6. Copy the token immediately — it starts with `ghp_` and won't be shown again

<Warning>
  Classic tokens grant access to **all repositories** your account can access, not just one. If your account has access to many repositories, prefer a fine-grained token to limit the blast radius.
</Warning>

### Step 2: Add the Integration in Amnify

Follow the same steps as [Method 1, Step 2](#step-2-add-the-integration-in-amnify) above.

***

## What Happens Next

Once connected, you can:

* Navigate to **Deploy → Templates** and click **Sync Templates** to import templates from your repository
* Browse and use synced templates when [creating Deployments](/cspm-deploy/guides/creating-deployments)
* [Add or modify templates](/cspm-deploy/guides/using-templates#adding-a-new-template) by pushing changes to your repository and syncing again

***

## Rotating Tokens

When your token expires, Amnify will no longer be able to sync templates. To rotate:

1. Generate a new token in GitHub following the steps above
2. Delete the existing GitHub integration in Amnify
3. Create a new integration with the new token

***

## Troubleshooting

| Issue                              | Cause                                            | Solution                                                                                                                                          |
| ---------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Sync fails with 401                | Token is invalid or expired                      | Generate a new token and recreate the integration                                                                                                 |
| Sync fails with 404                | Repository not found or token lacks access       | Verify the `owner/repo` format is correct and the token has access to that repository                                                             |
| No templates found after sync      | Repository doesn't follow the expected structure | Ensure templates are in a `templates/` directory — see [repository structure](/cspm-deploy/guides/using-templates#repository-directory-structure) |
| Fine-grained token shows "pending" | Organization requires admin approval             | Ask your GitHub organization admin to approve the token                                                                                           |
| Sync returns outdated templates    | Wrong branch configured                          | Verify the branch field matches where your templates live (defaults to `main`)                                                                    |
