# Git access: connection mode, Clone with Git, and GitHub

> Choose SFTP or Git mode, add an SSH key, clone and push over SSH, commit changes made on staging, or connect GitHub, GitLab, or any Git host.

Source: https://docs.wpwaterfall.com/git-access

Staging and each preview run in Git mode or SFTP mode, and you clone and push to them over SSH with a key on your account. Open the site, pick staging or a preview, and open **Info**: the **Code** card has the **SFTP | Git** switch, **Clone with Git**, uncommitted changes, and commit history.

Live has no Git access. Its code arrives only by a promote from staging. See [How Git deploys work](https://docs.wpwaterfall.com/code/git-workflow).

## What are the two modes?

| Mode | What changes code |
|---|---|
| **Git mode** (the default) | Only Git: a push, a merge, a pull from a connected repository, a promote, or a reset from live. Code is read only everywhere else. wp-admin cannot install or update plugins or themes, and the plugin and theme editors are off. Activating and deactivating plugins still works. |
| **SFTP mode** | SFTP, SSH, wp-admin plugin and theme installs and updates, WP-CLI, and the Files page. Click **Commit changes** to save the changes in Git. A Git push is pulled in when nothing is uncommitted. |

To switch, click the other side of the switch, then **Switch to Git mode** or **Switch to SFTP mode**. Switching to SFTP mode loses nothing: the working tree starts as a copy of the code the environment runs now. Switching to Git mode needs your uncommitted changes committed first, so the dialog asks for a commit message, or for you to tick **Discard my uncommitted changes instead**. While an external repository is connected, you cannot switch to SFTP mode, SFTP is off, and so are automatic updates and Safe Updates: the code arrives only from the repository, and WP Waterfall commits nothing back to it. The API answers 409 `external_repository_connected`. Disconnect the repository to use SFTP mode again. See [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github) and [Commit changes made over SFTP](https://docs.wpwaterfall.com/sftp-commits).

## How do I add an SSH key to my account?

You add a key once. It works on every staging and preview environment you may push code to, in every company you belong to.

1. Open **Account settings**, then **Integrations**, then the **SSH keys** tab. Integrations is under **Your account**.
2. Give the key a name you will recognize, such as `Work laptop`.
3. Paste the contents of your public key file, the one that ends in `.pub`. No key yet? Run `ssh-keygen -t ed25519 -C "you@example.com"` and paste `~/.ssh/id_ed25519.pub`. Never paste a private key.
4. Click **Add key**. If your account has a password, WP Waterfall asks for it first.

The key reaches an environment within a minute or so. You can keep up to 20 keys. To remove one, click **Remove** next to it. The key stops working for Git on your environments shortly.

### Who can use a key?

WP Waterfall accepts your key on an environment when you can deploy code to its site (the `code.deploy` permission):

| Role | Where your key works |
|---|---|
| Owner, Admin, Developer | Every staging and preview environment of the company |
| Site Admin, Site Developer | The staging and preview environments of the sites you were invited to |
| Billing, Viewer | Nowhere. These roles cannot push code. |

If you lose the permission, leave the company, or are removed from a site, WP Waterfall removes your key from those environments. A copy of the same key that you saved on one environment by hand (under **SFTP and SSH** on **Info**) stays until someone removes it.

## How do I clone and push?

Git over SSH turns on by itself for each staging and preview environment the first time someone opens it. It takes a few seconds, and until then the button says WP Waterfall is getting Git ready. If it says SSH is off, turn SSH on under **SFTP and SSH** on **Info**.

1. Add your SSH key to your account (above). Without one, the **Code** card shows an info icon that opens the **SSH keys** tab.
2. In the **Code** card, click **Clone with Git**, copy the address with **Copy**, and run:

   ```bash
   git clone ssh://USER@HOST:PORT/srv/git/site.git my-site
   ```

3. Push to the environment's branch: `master` for staging, and the branch's own name for a preview (`qa` for the preview named `qa`). In Git mode, WP Waterfall builds the new commit and runs it. In SFTP mode, it pulls the commit into the working tree when nothing is uncommitted. Otherwise the Code card says **New commits on master are waiting** and offers **Pull latest commits**.

Right after a push, Git prints what WP Waterfall is doing, for example:

```text
remote: WP Waterfall: Push received for staging (branch master).
remote: WP Waterfall: WP Waterfall is building a release from it and will switch staging to it.
remote: WP Waterfall: Follow it at https://my.wpwaterfall.com/dashboard/sites/SITE/info?env=ENV (job JOB).
remote: WP Waterfall: Then view staging at https://staging-acme.wpwaterfall.dev
```

A push may update only the environment's branch. It may not create or delete a branch, and it may not rewrite history (no force push). To use a new branch, create the preview in WP Waterfall first. Live is never pushed to. WP Waterfall checks this in the repository and again when it takes the push, so a refused push changes nothing. Customer hooks never run. To run the site on your computer with its database and uploads, see [Develop locally with DDEV](https://docs.wpwaterfall.com/develop-locally-with-ddev).

### What if a push is refused?

Git prints the reason after `remote:`.

| What Git prints | What to do |
|---|---|
| `Live takes code only by a promote from staging.` | Push to staging, then promote. |
| `This environment takes pushes to master only.` | Push to the branch the Code card names. Create a preview first for a new branch. |
| `This environment takes code from ... Push there.` | A GitHub or other repository is connected. Push to it, or disconnect it. |
| `this push is larger than 256 MB` | Push fewer files at a time. |
| `Permission denied (publickey)` | Check that the key your computer offers is the one on the **SSH keys** tab, and that your role can deploy code (see [Who can use a key?](#who-can-use-a-key)). Run `ssh -v` to see which key it tries. |

### How big can the repository get?

Each site repository has a 2 GiB allowance for everything in its history. Once it is over, WP Waterfall takes no more pushes and no more pulls from a connected repository. The job fails with "The repository of this site is over its 2 GiB allowance. Remove large files from its history or ask support." Rewrite the history to drop large files such as backups and videos, or ask support.

### What should stay out of the repository?

The repository is the whole site folder, and it is the web root, so anything in it is public and deployed. With DDEV, keep `.ddev`, `wp-config.php`, `wp-config-ddev.php`, and `wp-content/uploads` out of Git. `ddev wpwaterfall init` lists them in `.git/info/exclude`.

## Can I use HTTPS with a token?

Yes, for scripts and CI that cannot hold an SSH key. A token works as the password for `https://YOUR-ENVIRONMENT-HOSTNAME/_wpwaterfall/git/site.git` on one staging or preview environment. Create one with `POST /v1/environments/{id}/git/tokens`. The first token turns HTTPS Git on for the environment. The answer holds the token once, and WP Waterfall stores only a hash. A token is read only or read and write, expires after 90 days unless you pick up to a year, and works for one environment. Revoke a token with `DELETE /v1/environments/{id}/git/tokens/{token_id}?confirm=true`. Every token made, used, and revoked is in the activity log. Made from a signed in session, a token needs a password entered in the last 10 minutes. Live has no tokens, and a connected repository turns tokens off. For CI that can hold a key, save an SSH key on one environment with `POST /v1/environments/{id}/ssh-keys` and push over SSH. The workflows for both are in [Deploy from GitHub Actions](https://docs.wpwaterfall.com/github-actions).

## What happens to the repository when I delete the site?

It is deleted with the site, and this cannot be undone. Clone it first if you want to keep the history.

## How do I use GitHub, GitLab, or Bitbucket?

Open **Environments**, find the **External repository** card, and connect the repository with a read only deploy key and a webhook. While it is connected, SFTP and Git through WP Waterfall are off for staging and every preview: **Clone with Git**, the switch, and **Commit changes** give way to a line that names the repository. The steps, branch rules, and failures are in [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github).

## Why did my push not change the site?

- **Staging did not change.** In SFTP mode, staging waits while it has uncommitted changes. Commit or discard them, then click **Pull latest commits**. If the push said "WP Waterfall was not told", call `POST /v1/environments/{id}/git/import`.
- **Live did not change.** Live changes only by a promote. See [Promote to live](https://docs.wpwaterfall.com/code/git-workflow#promote-to-live).

## API

- `GET /v1/environments/{id}/git`: the mode, the WP Waterfall remote (`wpwaterfall_remote.ssh.status` is `ready`, `off`, `ssh_disabled`, `external`, or `live`, with the clone address in `wpwaterfall_remote.ssh.url` when ready), and the connected repository.
- `PUT /v1/environments/{id}/connection-mode` with `{"mode": "sftp"}` or `{"mode": "git"}`
- `POST /v1/environments/{id}/git/ssh`: turn on Git over SSH now. WP Waterfall does this by itself.
- `POST /v1/environments/{id}/git/import`: check for pushes
- `GET /v1/environments/{id}/git/tokens`, `POST /v1/environments/{id}/git/tokens` with `{"name": "laptop", "scope": "write", "expires_in_days": 90, "confirm": true}`, and `DELETE /v1/environments/{id}/git/tokens/{token_id}?confirm=true`
- `GET /v1/environments/{id}/working-tree`, `POST /v1/environments/{id}/commit`, `POST /v1/environments/{id}/working-tree/sync`
- `GET /v1/environments/{id}/ssh`, `POST /v1/environments/{id}/ssh-keys`, `DELETE /v1/environments/{id}/ssh-keys/{key_id}`: keys saved on one environment
- `GET /v1/users/me/ssh-keys`, `POST /v1/users/me/ssh-keys` with `{"name": "Work laptop", "public_key": "ssh-ed25519 AAAA..."}`, and `DELETE /v1/users/me/ssh-keys/{key_id}`: your account keys. These routes need a signed-in session. A plain API key cannot add or remove an SSH key, because a key is a standing way in to your code. The one exception is the connection of an AI assistant that you gave the `ssh-keys:write` scope, which asks you first each time (see [MCP connections](https://docs.wpwaterfall.com/mcp/overview#keys-and-ssh-keys)).

Routes for the external repository are in [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github).

## Related

- [How Git deploys work](https://docs.wpwaterfall.com/code/git-workflow)
- [Develop locally with DDEV](https://docs.wpwaterfall.com/develop-locally-with-ddev)
- [Deploys, rollback, and the Code card](https://docs.wpwaterfall.com/code-tab)
- [SSH and SFTP](https://docs.wpwaterfall.com/ssh-and-sftp)
- [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github)
- [Deploy from GitHub Actions](https://docs.wpwaterfall.com/github-actions)
- [Git and staging](https://wpwaterfall.com/features/developer-tools), the overview on wpwaterfall.com
