# How Git deploys work

> Push to staging over SSH or HTTPS, or from a connected repository, build, promote to live, and roll back. Live code is always read-only.

Source: https://docs.wpwaterfall.com/code/git-workflow

Every WP Waterfall site is a Git repository. Code changes on staging, and reaches live only by a promote. Live code is a read-only release, so nothing can change it from wp-admin, WP-CLI, SFTP, or a hacked plugin.

You see this page for one of three reasons. WordPress showed "Code is deployed from Git." on the Plugins, Themes, or Updates screen. A WP-CLI command such as `plugin install` was refused on live. Or you are setting up a new site.

## Why live code is locked

A plugin that gets hacked cannot write a web shell onto a read-only site, and a bad update cannot change files behind your back. Every change has a commit, a build log, and a person's name on the promote.

Uploads, caches, and the other [writable folders](https://docs.wpwaterfall.com/files-manager#which-folders-are-writable-on-live) stay writable. They never run PHP.

## How does code reach staging?

Staging and previews run in **Git mode** by default: code changes only through Git, as a read-only release. You can switch an environment to **SFTP mode** on its **Code** card to install from wp-admin or edit over SFTP, then commit. Every move of code between environments goes through Git and builds a release from a commit. See [Git access](https://docs.wpwaterfall.com/git-access) for the modes, the SSH key on your account, and [HTTPS tokens](https://docs.wpwaterfall.com/git-access#can-i-use-https-with-a-token) for CI.

To keep your code on GitHub, GitLab, or Bitbucket instead, see [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github). The repository holds your site folder except uploads, caches, and `wp-config.php`, which WP Waterfall writes for each environment.

## Change code and push

Commit and push to `master`, staging's branch. A preview is also a Git branch with the same name, such as `qa`. A push never creates a branch: create the preview in WP Waterfall first.

```bash
git add wp-content/themes/my-theme/style.css
git commit -m "Update the theme header color"
git push origin master
```

With the DDEV add-on, `git push wpwaterfall master` does the same, and `ddev wpwaterfall push --code` checks the target first. The add-on refuses a push when the environment is live, when SSH is off, or when an external repository is connected, and nothing is sent. To send a database or uploads too, see [Push code to staging](https://docs.wpwaterfall.com/push-code-to-staging).

Git prints `Push received for staging (branch master).` and a link to follow the build. [Git access](https://docs.wpwaterfall.com/git-access#what-if-a-push-is-refused) lists the other messages Git can print.

To add a plugin or theme, put its folder under `wp-content/plugins` or `wp-content/themes`, or add it with Composer and a build step in [`wpwaterfall.yml`](https://docs.wpwaterfall.com/code/wpwaterfall-yml).

WP Waterfall builds the new commit in a fresh container, runs the steps in `wpwaterfall.yml`, and switches staging to it. If a step fails, staging keeps the code it had.

### Why does live refuse a push?

Live takes no account SSH keys or Git tokens and its code is read only, so a push has nowhere to go. To change live, push to staging and promote. To copy live's data into staging, reset staging from live. To put staging's database and uploads into live, use [Copy staging into live](https://docs.wpwaterfall.com/push-environments), which warns you and takes a restore point first.

## Promote to live

When staging is ready, open **Info** on staging and click **Promote to live** in the **Environment details** card. On live, the **Deploys** card has **Deploy to live**. The dialog lists the commits and files live lacks. Confirm, and WP Waterfall:

1. Builds the commit and takes a restore point of live.
2. Mounts the new release read-only at the site root.
3. Resets OPcache.
4. Runs your [deploy hooks](https://docs.wpwaterfall.com/code/wpwaterfall-yml#deploy-hooks).
5. Clears the server cache.

If a deploy hook fails, live keeps the code it had. The activity log shows who promoted. From a preview, merge into staging first. A promote moves code only, unless you choose content to copy in the dialog.

## Roll back

WP Waterfall keeps the release live runs and the one before it, so a rollback always has a release to return to. Pick **Live**, open **Info**, click **Deploys** in **Environment details**, then **Roll back** next to the earlier release. Right after a promote, the dialog also offers **Undo**. The older code goes live without a new build.

Rollback changes code only. Your database and uploads stay as they are.

## What if a plugin writes into its own folder?

A plugin that writes into its own folder under `wp-content/plugins` or `wp-content/themes` fails on live, because that folder is code and live code is read-only. The PHP error log shows the failed write. Ask the plugin's author for a setting that keeps its files in uploads, or run it on staging. If a plugin needs to write code and run it on live, it cannot work on WP Waterfall.

## Environment variables and secrets

Keep keys, tokens, and passwords out of the repository. Set them per environment on the **Environment variables** card on **Info**. See [Environment variables](https://docs.wpwaterfall.com/environment-variables).

## Quick answers

**WP-CLI refused `plugin install` on my live site. What now?**
Add the plugin to your repository and push it to staging, or switch staging to SFTP mode, install it in wp-admin, commit, and promote.

**wp-admin on staging says "This environment is in Git mode." Is something broken?**
No. Push the change with Git, or choose **Switch to SFTP mode** on the **Code** card to install from wp-admin.

**wp-admin has no Add New button on the Plugins screen on live. Is something broken?**
No. Live code is read-only, so WordPress hides it on purpose.

**I changed a file on live in the file manager and my change disappeared.**
Code folders are read-only on live. Make the change on staging (by a Git push, or in SFTP mode) and promote it. Files in uploads and cache are the exception: they take changes on live and stay.

## Related

- [wpwaterfall.yml reference](https://docs.wpwaterfall.com/code/wpwaterfall-yml)
- [Git access](https://docs.wpwaterfall.com/git-access)
- [Staging, live, and preview environments](https://docs.wpwaterfall.com/environments)
