Last updated: · By Asael Dreyer
Short answer: to run a Git deployment, meaning deploying code from Git to Cloudways, open Deployment via Git in the application, click Generate SSH Keys, add the public key to GitHub, Bitbucket or GitLab, paste the repository’s SSH address, choose a branch and a path, and click Start Deployment. From then on, every update is a click on Pull. On Flexible you can also automate it: a webhook in the repository that triggers the Cloudways API on every push. On Autonomous, deployment is under Workflow/Tools.
⏱ Time: 15 minutes for the first connection, 30–45 minutes for automatic deployment · Difficulty: intermediate (developers) · Last checked against the official docs: 6 Nov 2026
How deploying from Git works on Cloudways
Before the buttons, a few concepts that will save you some surprises.
Git is a version control system for code. Your code lives in a repository with a provider like GitHub, and a deployment is copying the latest version of a given branch from the repository to the server.
On Cloudways, deployment is a Pull: the server pulls the code from the repository. For the server to be allowed to read from the repository, it identifies itself with an SSH key. Cloudways generates a key pair, and you add the public key to the repository as a Deploy Key, a key that gives access to one repository only. That’s why a connection only works with the repository’s SSH address (git@github.com:…), not with an HTTPS address.
Four behaviors worth knowing, because they aren’t always what you’d expect:
- A deployment doesn’t delete files. A file that exists in the folder on the server but not in the repository stays. A Pull updates and adds, it doesn’t clean up.
- A Pull overwrites changes made over SFTP. A file you edited directly on the server will be replaced by the repository version on the next deployment, if it exists there.
- Restoring a backup overwrites everything. After a restore, another Pull will update the files to the latest version in the repository.
- Removing the connection doesn’t delete anything. Remove only deletes the application’s Git settings, not files and not the repository.
What to put in Git on a WordPress site
On a WordPress site, you almost never deploy the whole site from Git. WordPress core and plugins are updated from the dashboard, and the uploads folder exists only on the server. The common pattern is a repository that contains only the theme (or a custom plugin), and a deployment path that points to its folder, for example public_html/wp-content/themes/my-theme/.
As for wp-config.php and other configuration files: according to Cloudways, there’s no way to “protect” a file from being overwritten. A file that shouldn’t change on deployment shouldn’t be tracked by Git in the first place. Remove it from the repository (untrack it) and add it to .gitignore.
Before you start
- A repository with a provider that supports Git over SSH: GitHub, GitLab, Bitbucket and the like.
- Admin permissions on the repository, so you can add a Deploy Key and a webhook.
- An existing site (application) on Cloudways. I recommend connecting Git first to a staging environment, testing there, and only then moving to the live site.
- A backup of the application before the first deployment, especially if the path is public_html with existing files.
How to deploy from the panel on Flexible
Step 1: generate an SSH key on Cloudways
- In the panel click Flexible in the side menu, and on the screen that opens, the Servers tab. Choose the server, click the globe icon and choose the application.
- In the application’s left menu click Deployment via GIT.
- Click Generate SSH Keys.
- Click View SSH Key and copy the public key (or download it as a git_ssh_key.txt file).

Step 2: add the key to the repository on GitHub
- On GitHub open the repository and click Settings.
- In the side menu choose Deploy keys and click Add deploy key.
- Give it a name (for example “Cloudways – staging”) and paste the key into the Key field.
- Deploying from the panel doesn’t need write access, so leave Allow write access off. Click Add key.
Bitbucket and GitLab have an equivalent option called Access keys or Deploy keys in the repository settings.
Step 3: connect the repository and run the first deployment
- On GitHub click the green Code button, choose SSH and copy the address (git@github.com:user/repo.git).
- On Cloudways paste it into the Git Remote Address field and click Authenticate. This checks that the server can talk to the repository.
- Choose a branch. The default is master, and for most newer repositories you’ll need to choose main.
- Enter the Deployment Path: the folder the code will be copied to. End it with
/. If you leave it empty, the code is deployed to public_html. - Click Start Deployment and wait for the message that the deployment has finished.
After the first deployment, buttons for managing the connection appear: Pull (pulling the latest changes), changing the branch, and Remove. The View Deployment Logs button shows when and by whom a deployment was run, which is especially useful when several developers work on the same site.
How to deploy from Git on Cloudways Autonomous
Autonomous follows the same idea, in a different place and with one difference in the key.
- In the panel go to Autonomous and choose the application from My Applications.
- In the application’s top menu click Workflow/Tools, and in the side menu Deployment via GIT.
- Click Generate SSH Keys (it can take a few minutes), then View SSH Keys and copy the key, or download it with Download SSH Key.
- On GitHub, according to the Autonomous docs, you add the key under your account’s Settings, then SSH and GPG keys and New SSH key.
- Copy the repository’s SSH address, paste it into GIT Remote Address and click Authenticate.
- Choose a branch, confirm the Deployment Path (usually public_html/), and click Start Deployment.
- From here, updates are a click on Pull.
Note the difference: a key you add to a GitHub account (rather than as a Deploy Key on a repository) gives access to every repository that account can see. If you can, use a dedicated GitHub account for deployment with access only to the relevant repositories, or add the key as a Deploy Key on the repository itself. According to the docs, Autonomous supports GitHub, GitLab, Bitbucket and Assembla.
How to work with Git on the command line (SSH)
The panel only knows how to pull. If you need to work with Git on the server itself, for example to push changes back to the repository, switch branches or clone, you do it over SSH. Git (version 2.30.x according to the docs) comes preinstalled on every server.
Important: you need the Master Credentials. Application credentials don’t let you create and read SSH keys in the default location. A team member without master access can only use deployment from the panel.
- Connect over SSH with the master user.
- Create a key (Enter to save it in the default location, and Enter twice for an empty passphrase):
ssh-keygen -t rsa -b 4096 -C "you@example.com"
cat /home/master/.ssh/id_rsa.pub
- Add the public key as a Deploy Key on the repository, and this time tick Allow write access if you want to push from the server. Note: the key is created without a passphrase, as in the docs, so anyone who reaches the master user’s .ssh folder can use it. Add it as a Deploy Key to a single repository, not to your GitHub account.
- Work from inside the application’s folder. I recommend private_html, because if you clone a repository into public_html, the .git folder may be accessible from a browser:
cd applications/APP_FOLDER/private_html
git clone git@github.com:user/repo.git
cd repo
git checkout -b feature-x
git add .
git commit -m "Describe the change"
git push origin feature-x
Two things to remember: the key created in the panel only works for deployment from the panel, and the key you created over SSH only works on the command line. According to the docs, you can add the same public key to several repositories connected to sites on the same server. On GitHub, a Deploy Key is unique to one repository, so for another repository create a separate key (ssh-keygen -f) or use an account-level key.
How to set up automatic deployment with a webhook (Flexible)
A webhook is an automatic message the repository sends to an address of your choice every time someone pushes. On Cloudways you connect it to a small PHP script on the site, which calls the Cloudways API and requests a Pull. The result: a push to the main branch, and the site updates itself within a minute or two. For a custom PHP application, not just WordPress, see managed PHP hosting.
Requirements according to the docs: you’re the primary account owner, the application is on a Flexible server, and deployment from the panel is already set up and working (Cloudways’ key is already in the repository).
Step 1: create an API Access Token
Cloudways is replacing the old API key (API Key) with API Access Tokens. Don’t build a new integration on the old key.
- In the panel click the profile icon in the top right corner and choose API Integration. (The official docs also describe going in through the grid icon in the side menu.)
- In the Access Token Details area click Create Access Token.
- Give it a clear name, for example “Git Webhook – store site”, and choose an expiry.
- Under permissions choose Limited Access, with only the Git action needed for deployment. Full Access only if you have no choice.
- Click Create Access Token and copy it right away. The token is shown only once.

When the token expires, automatic deployment will stop silently. Put a reminder in your calendar to renew it before the expiry date.
Step 2: gather the details
- Server ID and Application ID: they appear in the browser URL when you open the server and the application in the panel.
- The repository’s SSH address and the branch to deploy.
- The deployment path, or empty for public_html.
- A long, random webhook secret (not one of your passwords and not the token), at least 20 characters. You can generate one on the server with the command
openssl rand -hex 32.
Step 3: a configuration file outside public_html, and the deployment script
Using SFTP or SSH, in the application folder above public_html (not inside it), create a file named gitautodeploy-config.php:
<?php
return [
'access_token' => 'PASTE_YOUR_ACCESS_TOKEN',
'webhook_secret' => 'LONG_RANDOM_SECRET',
'server_id' => '123456',
'app_id' => '7890123',
'git_url' => 'git@github.com:user/repo.git',
'branch_name' => 'main',
'deploy_path' => '',
];
Then, inside public_html, a file named gitautodeploy.php. This is my own version, and it deliberately differs from the official script in one respect: the secret isn’t sent in the URL (?secret=) but is checked against a signature in the request header, because URLs get stored in server logs and browser history. The script accepts only POST, verifies the sender (GitHub and Bitbucket Cloud with an HMAC signature, GitLab with a token in the header), ignores a push to a different branch, and only then sends the Cloudways API a Pull request with the token in the Authorization header:
<?php
declare(strict_types=1);
$configFile = dirname(__DIR__) . '/gitautodeploy-config.php';
if (!is_file($configFile)) {
http_response_code(500);
exit('Missing configuration file');
}
$config = require $configFile;
$secret = (string) ($config['webhook_secret'] ?? '');
if (strlen($secret) < 20 || empty($config['access_token'])) {
http_response_code(500);
exit('Incomplete configuration');
}
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
header('Allow: POST');
http_response_code(405);
exit('POST only');
}
// Verify the sender: GitHub (X-Hub-Signature-256), Bitbucket Cloud (X-Hub-Signature)
// or GitLab (X-Gitlab-Token). The secret never appears in the URL.
$body = (string) file_get_contents('php://input');
$expected = 'sha256=' . hash_hmac('sha256', $body, $secret);
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? $_SERVER['HTTP_X_HUB_SIGNATURE'] ?? '';
$gitlabToken = $_SERVER['HTTP_X_GITLAB_TOKEN'] ?? '';
$valid = ($signature !== '' && hash_equals($expected, $signature))
|| ($gitlabToken !== '' && hash_equals($secret, $gitlabToken));
if (!$valid) {
http_response_code(403);
exit('Invalid signature');
}
// GitHub sends a "ping" when the webhook is created.
if (($_SERVER['HTTP_X_GITHUB_EVENT'] ?? '') === 'ping') {
exit('pong');
}
// Deploy only pushes to the configured branch.
$payload = json_decode($body, true);
$pushed = '';
if (is_array($payload)) {
if (isset($payload['ref'])) {
$pushed = (string) preg_replace('#^refs/heads/#', '', (string) $payload['ref']);
} elseif (isset($payload['push']['changes'][0]['new']['name'])) {
$pushed = (string) $payload['push']['changes'][0]['new']['name'];
}
}
if ($pushed !== '' && $pushed !== (string) $config['branch_name']) {
http_response_code(202);
exit('Ignored: not the deploy branch');
}
$params = [
'server_id' => $config['server_id'],
'app_id' => $config['app_id'],
'git_url' => $config['git_url'],
'branch_name' => $config['branch_name'],
];
if (!empty($config['deploy_path'])) {
$params['deploy_path'] = $config['deploy_path'];
}
$ch = curl_init('https://api.cloudways.com/api/v1/git/pull');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $config['access_token']],
CURLOPT_POSTFIELDS => http_build_query($params),
]);
$response = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false) {
http_response_code(502);
exit('Cloudways API is unreachable');
}
if ($status < 200 || $status >= 300) {
http_response_code($status);
exit('Cloudways API returned HTTP ' . $status);
}
echo 'Deployment request submitted';
A few decisions in the script, for anyone who wants to understand them: the token and the secret sit in a file outside public_html, comparisons are done with hash_equals (no timing leaks), the details sent to the API are fixed in the config file and don’t come from the request, and the API’s response isn’t returned to the sender.
Don’t put the config file in the repository. Add its name to .gitignore.
Step 4: add the webhook in the repository
The webhook URL is just the address of the file: https://yourdomain.com/gitautodeploy.php, with no secret in the URL. You enter the secret in the webhook’s secret field at your Git provider, and the provider signs every request with it. Use HTTPS. In Cloudways’ official script the secret appears in the URL, so if you go with that one, treat the URL like a password.
On GitHub:
- In the repository click Settings, then Webhooks and Add webhook.
- In Payload URL paste the address.
- For Content type choose
application/json. Cloudways’ docs say application/x-www-form-urlencoded, but my script reads JSON so it can filter by branch. - In Secret paste the secret from the config file.
- Choose Just the push event, make sure the webhook is Active, and click Add webhook.
On Bitbucket: Repository settings, under Workflow choose Webhooks and then Add webhook, give it a name, paste the address, enter the secret in the Secret field, choose the push event and save.
On GitLab: Settings, Webhooks, the address, the secret in the Secret token field and the Push events event. GitLab now recommends a signing token instead of a Secret token, and the script here only checks the Secret token.
Step 5: test it
- Make a small change on the branch you configured, then commit and push.
- In the repository, open the webhook’s delivery history and check that a successful response was received. A 202 response means the push was to a different branch, so no deployment was run.
- Check on the site that the change arrived. A successful response means the request was received. The Pull itself can take a moment.
| Error code | What it means | What to check |
|---|---|---|
| 400 | Missing or incorrect information | Server ID, App ID, repository address, branch name, path |
| 401 | The token isn’t valid | Was it copied correctly? Has it expired? Was it revoked? |
| 403 | A wrong signature or secret, or the token lacks permission | Is the secret in the Secret field at your Git provider identical to the one in the file? Does the token have Git permission? |
| 405 | The request wasn’t sent as POST | The webhook settings in the repository |
The code BFCM802 takes 80% off your bill for the first two months (up to $200 off per month), including unlimited free site migrations. New customers only, and only until the offer ends.
The offer ends on December 4, 2026 at 23:59 (UTC+2).
Start with a free trial, no credit card. Enter the code at checkout and check that it shows up.
After Black Friday: 30% off for 3 months with the code ASAEL. On a large server (above about $444 a month) ASAEL already saves more today. BFCM802 vs. ASAEL calculator
Start a free trial server, no credit card. When you move to a paid plan, the code ASAEL takes 30% off your bill for the first three months.
The link fills in the code on the signup form. Just make sure it shows up.
Recommended workflow: Git, staging and the live site
A common working pattern for agencies and developers on Cloudways:
- The
developbranch is connected to the staging application, andmainto the live site. - You develop and test on staging, including with real data copied from the live site.
- When it’s approved, you merge into main, and the webhook (or a manual Pull) updates the live site.
- The database doesn’t travel through Git. Changes to content and settings move through staging’s push tools or manually.
Details on staging, cloning and pulling a site down for development are in the guide to cloning a site for development. Agencies managing dozens of sites will find more tools on the Cloudways for agencies page.

Common mistakes and how to fix them
Authenticate fails: you pasted an HTTPS address instead of SSH, or Cloudways’ key wasn’t added to the repository. Make sure the address starts with git@.
The deployment “succeeded” but the files aren’t in the right place: the deployment path is wrong or doesn’t end with /. Check the folder where the files landed.
Old files remained after a deletion in the repository: that’s the normal behavior. A Pull doesn’t delete files that don’t exist in the repository. Delete them manually on the server.
An urgent change you made over SFTP disappeared: a Pull overwrote it. Every change needs to go through the repository.
A team member can’t run Git over SSH: application credentials don’t allow creating keys. They need master access, or to work through the panel.
Automatic deployment stopped after a few months: almost always the token expired. Create a new token, update the config file, and revoke the old one.
A push to main didn’t trigger a deployment: the push was to a different branch from the one in the config file (the script returns 202), or the selected event isn’t a push. Check the delivery history in the repository.
403 Invalid signature despite a correct secret: the secret wasn’t entered in the webhook’s Secret field, it was pasted with a trailing space, or it differs from the value in gitautodeploy-config.php.
Sources
This page is based on the following official docs and pages:
- How to deploy code to your application using Git on Cloudways Flexible (Cloudways Knowledge Base)
- How to deploy code to your application using Git on Cloudways Autonomous (Cloudways Knowledge Base)
- Using Git via command line (Cloudways Knowledge Base)
- How to automatically deploy from Git to Cloudways using Webhooks (Cloudways Knowledge Base)
FAQ
Any provider that supports Git over SSH, including GitHub, GitLab and Bitbucket. For Autonomous the docs explicitly list GitHub, GitLab, Bitbucket and Assembla. HTTPS addresses aren’t supported, only SSH.
No. It updates files that exist in the repository and adds new ones, but files that exist only on the server stay. Removing the connection doesn’t delete files either.
Yes, and it’s the recommended pattern. Set the deployment path to the theme folder, for example public_html/wp-content/themes/my-theme/, and the repository contains only the theme.
Not as a built-in button, but on Flexible you can build it with a webhook in the repository, a small PHP script and an API Access Token, following the instructions in this guide. It takes about half an hour the first time.
The key created in the panel is used only for deployment from the panel and for the webhook. The key you create over SSH with the master user is used only for Git commands on the command line, such as pushing from the server.
Yes, under Workflow/Tools and then Deployment via GIT, with a one-click Pull. Webhooks for automatic deployment are currently documented only for Flexible.
Related guides
- How to create a staging environment on Cloudways
- How to clone a site or pull it down for development
- Connecting to your server over SSH
- Cloudways for agencies
- All guides on this topic: Staging, cloning and Git
Official source: Deploy Code Using Git on Cloudways Flexible, Deploy Code Using Git on Cloudways Autonomous, Using Git via Command Line, Automatically Deploy From Git Using Webhooks (Cloudways Knowledge Base). Written and checked by Asael · Updated: 6 Nov 2026
Disclosure: this is an independent site, not the official Cloudways site. Some links on this site are affiliate links: if you sign up through them we earn a commission, at no extra cost to you. Full details