# Connect GitLab or Bitbucket

Once GitLab or Bitbucket is connected, its repositories show up in **Add an app**, and pushes start deploys within seconds.

## Connect

1. Open **Settings**, **Git**, and connect GitLab or Bitbucket.
2. Approve the access it asks for:

| Provider  | Access                                                                                          |
| --------- | ----------------------------------------------------------------------------------------------- |
| GitLab    | `read_repository`, `read_api` and `api`. Coresmith needs `api` to add deploy keys and webhooks. |
| Bitbucket | `repository`, `webhook` and `repository:admin`.                                                 |

Coresmith uses the connection to list repositories and to tell your provider to report pushes. To get the code, each app gets its own read-only deploy key, which Coresmith adds to the repository. An app can read only its own repository.

## On self-hosted Coresmith

A self-hosted install needs an OAuth app of your own at GitLab or Bitbucket. Until one is set up, **Settings**, **Git** says the provider isn't set up on this install.

1. Create an OAuth app at GitLab or Bitbucket with the access above. Its callback address is Coresmith's address followed by `/settings/source-providers/gitlab/callback`, or `/settings/source-providers/bitbucket/callback`.
2. On Coresmith's server, add its ID and secret to `/opt/coresmith/shared/.env`, as `GITLAB_CLIENT_ID` and `GITLAB_CLIENT_SECRET`, or `BITBUCKET_CLIENT_ID` and `BITBUCKET_CLIENT_SECRET`.
3. Load them:

```bash
cd /opt/coresmith/app && sudo -u coresmith php artisan config:cache && sudo -u coresmith php artisan horizon:terminate
```

## Disconnect

Disconnecting revokes Coresmith's access and forgets the connection. The deploy keys stay on each repository, so existing apps keep deploying.
