# GitHub and GitHub Enterprise

Source: https://openpanel.sh/docs/git/github

Connect a github.com or GitHub Enterprise Server account to OpenPanel with a classic or fine-grained personal access token, and which scopes it needs.

A GitHub account reads every repository its token can read. It works with github.com and with GitHub Enterprise Server.

## The token [#the-token]

Use either kind of personal access token:

| Token | Scopes or permissions |
|---|---|
| **Classic** | `repo` and `read:user` |
| **Fine-grained** | Read access to **Contents** and **Metadata**, for the repositories you choose |

<Tabs items={["Classic token","Fine-grained token"]}>
<Tab value="Classic token">
1. Open [github.com/settings/tokens/new?scopes=repo,read:user&description=OpenPanel](https://github.com/settings/tokens/new?scopes=repo,read:user&description=OpenPanel). The add dialog links to the same page, with the note and the two scopes already filled in.
2. Choose an expiration.
3. Check that **repo** and **read:user** are ticked, and choose **Generate token**.
4. Copy the token. GitHub shows it only once.

The classic `repo` scope also allows writing to your repositories. OpenPanel only reads; for read-only access, use a fine-grained token.
</Tab>

<Tab value="Fine-grained token">
1. On GitHub, open **Settings** → **Developer settings** → **Personal access tokens** → **Fine-grained tokens**, and choose **Generate new token**.
2. Choose the **Resource owner** (you or an organization) and an expiration.
3. Under **Repository access**, choose all repositories or only some.
4. Under the repository permissions, give **Contents** read-only access. Read-only **Metadata** is always included.
5. Choose **Generate token**, and copy it.
</Tab>
</Tabs>

On **GitHub Enterprise Server**, make the token on your server's own address: the add dialog links to `/settings/tokens/new` there once you have typed the address.

## Add the account [#add-the-account]

1. In **Organization settings** → **Git accounts**, choose **Add Git account** → **GitHub**.
2. **Address**: leave `https://github.com`, or enter your GitHub Enterprise Server's address.
3. Paste the token into **Personal access token**, and choose **Add account**.

OpenPanel checks the token at once and shows whose it is and how many repositories it reads. If the check fails, nothing is saved.

GitHub Enterprise Server must be reachable from the internet: GitHub accounts cannot be reached through the private network. OpenPanel calls its API at the address you entered, under `/api/v3`.

## If the check fails [#if-the-check-fails]

| The console says | What to do |
|---|---|
| GitHub did not accept the token. Check that it was copied whole and has not expired or been revoked. | Copy the token again, whole, or make a new one. |
| GitHub refused the token for this. It needs: … | Give the token the scopes or permissions above. |
| Nothing answered at …/user. Check the address (GitHub Enterprise Server answers at its own address, with the API under /api/v3). | Check the Enterprise Server address. |
| GitHub is limiting requests from this address. Try again later. | Wait, then choose **Check again**. |

When a token expires, the account shows **Failed** at its next check. Remove the account and add it again with a new token.