Last updated

WordPress

Sync WordPress to GitLab

Sync your WordPress theme and plugin files to a private GitLab repository.

Contents

  1. Initialize a Git Repo in Your Theme
  2. Create a .gitignore
  3. Push Initial Commit
  4. GitLab CI/CD Pipeline (.gitlab-ci.yml)
  5. Set Up SSH Key in GitLab

Version control your WordPress theme and plugins with GitLab, with optional CI/CD deployment.

Initialize a Git Repo in Your Theme

cd /var/www/html/wp-content/themes/your-theme
git init
git remote add origin git@gitlab.com:youruser/your-theme.git

Create a .gitignore

# .gitignore
node_modules/
*.log
.DS_Store
wp-config.php
wp-content/uploads/

Push Initial Commit

git add .
git commit -m "Initial theme commit"
git push -u origin main

GitLab CI/CD Pipeline (.gitlab-ci.yml)

stages:
  - deploy

deploy-production:
  stage: deploy
  only:
    - main
  script:
    - which rsync || apt-get install -y rsync
    - rsync -avz --exclude='.git' ./ user@yourserver:/var/www/html/wp-content/themes/your-theme/
    - ssh user@yourserver "sudo systemctl reload nginx"

Set Up SSH Key in GitLab

  • Generate a deploy key: ssh-keygen -t ed25519 -f ~/.ssh/gitlab-deploy
  • Add the public key to GitLab: Project → Settings → Repository → Deploy Keys
  • Add the private key as a CI variable: Settings → CI/CD → Variables → SSH_PRIVATE_KEY

FAQ

Why keep WordPress code in Git?

You get history, rollbacks and safe deployments for themes and custom plugins.

Should uploads and the database go in Git?

No. Keep Git for code; back up uploads and the database separately.