# Connecting GitHub

Source: https://docs.apphaven.eu/github

Connect your GitHub account once, and AppHaven deploys your repositories
automatically: every push to your production branch becomes a new release,
and pushes to your preview branches become preview deployments. The connection
uses the AppHaven GitHub App, so access stays scoped to exactly the
repositories you choose, and you can change or revoke it on GitHub at any
time.

## Install the AppHaven GitHub App

1. Open your application in the console and go to the **Source** tab.
2. Choose **Connect with GitHub**. You are taken to GitHub to install the
   AppHaven app.
3. Pick the account or organization that owns your repository.
4. Choose which repositories AppHaven may see. **Only select repositories**
   is the recommended option: pick just the ones you plan to deploy. You can
   add more later from GitHub's settings.
5. Confirm with **Install**. GitHub returns you to the console, where the
   repository list is ready to use.

Installing for an organization may require an owner's approval, depending on
the organization's settings. If your repository does not appear in the list
after installing, an approval is usually still pending: an organization owner
can grant it under **Settings, GitHub Apps** in the organization.

## What AppHaven can access

The app requests read access to the contents of the repositories you
selected, and receives a notification when you push. It cannot see other
repositories, and it never writes to your code.

## Pick the repository and branch

Back in the **Source** tab, select the repository and the **production
branch** (usually `main`). Pushes to the production branch become production
releases.

Pushes to other branches deploy only if the branch matches your preview branch
pattern, which defaults to `preview/*`. The pattern and the number of previews
you can run at once are set in the same tab, and are covered in
[preview deployments](https://docs.apphaven.eu/previews.md).

## Changing or removing access

Manage the installation from GitHub under **Settings, Applications** (for a
personal account) or the organization's **Settings, GitHub Apps**. There you
can add repositories, remove them, or uninstall the app entirely. Removing a
repository stops new deployments for it; running deployments keep serving
until you remove them in the console.

If AppHaven can't access the repository, it says so: "AppHaven can't access
this repository. It may have been transferred, renamed or deleted, or the
GitHub App lost access. Use Change to reconnect it." Until then, pushes may not
reach AppHaven. A short GitHub outage can cause the same warning; it clears by
itself on the next successful check. `apphaven app` and `apphaven status` start
with the same warning, with the reason and since when, and `apphaven app --json`
carries it as `source.pollError` and `source.pollErrorAt`. Anyone with
developer access can reconnect the repository with **Change** on the app's
**Source** page.

## Using another Git host

You do not need GitHub to use AppHaven. The **Connect repository** form on
the same Source tab accepts an HTTPS clone URL from any Git host; supply a
username and a read-only access token for private repositories. See
[Getting started](https://docs.apphaven.eu/getting-started.md#2-connect-your-repository).
