Version control your WordPress theme and plugins with GitLab, with optional CI/CD deployment.
Category: WordPress
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