How to deploy my site with Git
Deploying with Git means you push code to your repository and pull it onto the server, instead of uploading files by FTP.
What's available
| Panel | Method |
|---|---|
| cPanel | Files → Git Version Control: clone a repository, pull updates, and run a deployment script from the browser. No SSH needed for public repositories |
| DirectAdmin | No built-in Git screen. Use Git over SSH. SSH is off by default; open a support ticket to enable it. See How to get SSH access and connect |
cPanel: Git Version Control
Step 1: Clone the repository
- Go to Files → Git Version Control.
- Click Create.
- Leave Clone a Repository on.
- Clone URL: paste the repository's clone URL. For a public repository, the HTTPS URL works. For a private repository, see Private repositories below.
- Repository Path: a folder outside
public_html, for examplerepositories/mysite. Don't clone straight intopublic_html, or the.gitfolder becomes web-accessible. - Repository Name: anything you like.
- Click Create.
Step 2: Add a deployment file
cPanel deploys by running the tasks in a file called .cpanel.yml at the root of your repository. Commit this file to the repository:
---
deployment:
tasks:
- export DEPLOYPATH=/home/username/public_html/
- /bin/cp -R public/* $DEPLOYPATH
Replace username with your cPanel username and public/* with the folder in your repository that holds the site's files. To copy the whole repository, use /bin/cp -R * $DEPLOYPATH.
Keep tasks simple: copying files, removing a cache folder. Run Composer, npm and build steps on your computer before committing, or over SSH.
Step 3: Deploy
- In Git Version Control, click Manage next to the repository.
- Open the Pull or Deploy tab.
- Click Update from Remote to fetch the latest commit.
- Click Deploy HEAD Commit. cPanel runs your
.cpanel.ymltasks.
Repeat steps 3 and 4 after every push.
Deploy HEAD Commit is greyed out? Either the repository has no .cpanel.yml, or the copy on the server has uncommitted changes. Don't edit files inside the repository folder on the server; edit locally, commit, push, pull.
Private repositories
A private repository's HTTPS URL asks for a password, which the cPanel tool can't answer. Use an SSH deploy key instead:
- In cPanel go to Security → SSH Access → Manage SSH Keys → Generate a New Key. Leave the passphrase blank and click Generate. If you don't see SSH Access, open a support ticket and we'll set the key up for you.
- Back on Manage SSH Keys, click Manage next to the new public key and Authorize it.
- Click View/Download next to the public key and copy it.
- In GitHub, GitLab or Bitbucket, open the repository → Settings → Deploy keys → Add deploy key. Paste the key. Read-only is enough.
- In Git Version Control, clone using the SSH URL, for example
git@github.com:you/mysite.git.
Automatic deployment on push
cPanel deploys when you click. To deploy on every push, use a GitHub Action or GitLab pipeline that uploads over FTP (many ready-made actions exist). Store the FTP details as secrets in the repository, never in the code.
DirectAdmin: Git over SSH
-
Have SSH enabled by support, then connect. See How to get SSH access and connect.
-
Clone the repository outside
public_html:cd ~ git clone git@github.com:you/mysite.git repositories/mysiteFor a private repository, first create a key with
ssh-keygen -t ed25519, then add the contents of~/.ssh/id_ed25519.pubas a deploy key on the repository. -
Copy the site files into place (DirectAdmin's website folder is
~/domains/yourdomain/public_html):rsync -av --exclude '.git' ~/repositories/mysite/public/ ~/domains/yourdomain/public_html/Adjust
public/to your repository's web folder. -
To update later:
cd ~/repositories/mysite && git pull && rsync -av --exclude '.git' public/ ~/domains/yourdomain/public_html/
Save that line as a small script so deployment is one command.
Things not to commit
.envfiles,wp-config.php, or anything with passwords. Create them on the server once.- Uploaded user content (
wp-content/uploads). Keep it on the server only. vendorandnode_modules, unless you have no way to run the install on the server.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| "Repository path must be empty" when cloning | Folder already has files | Choose a new folder, or empty it |
| Clone fails with "Permission denied (publickey)" | Deploy key not added, or wrong URL type | Add the public key to the repository. Use the SSH URL |
| Clone asks for a username and password | Private repository over HTTPS | Switch to the SSH URL with a deploy key |
| Deploy button greyed out | No .cpanel.yml, or local changes in the server copy |
Commit the file. Don't edit files in the repository folder on the server |
| Deployed but the site shows old files | Copied to the wrong path, or a page cache | Check DEPLOYPATH. Purge caches |
.git folder reachable at yourdomain/.git |
Cloned straight into public_html |
Move the repository outside and deploy with copy tasks |
Did this answer it?