Skip to main content

Git Integration

Use Git to version control your WordPress site and push changes directly to staging.

Clone Your Staging Site​

Download your staging site's code to your local machine:

git clone ssh://[email protected]/var/www/html mysite-staging
cd mysite-staging

Set Up Staging as a Remote​

If you already have a local repository, add staging as a remote:

cd my-wordpress-project
git remote add staging ssh://[email protected]/var/www/html

Push Changes to Staging​

After making changes locally:

git add .
git commit -m "Update theme styles"
git push staging main

Your changes are immediately reflected on the staging site.

Pull Changes from Staging​

If changes were made on staging (via WP-CLI, file uploads, etc.):

git pull staging main

Typical Workflow​

# 1. Clone or set up the remote
git clone ssh://[email protected]/var/www/html mysite
cd mysite

# 2. Create a feature branch
git checkout -b feature/new-header

# 3. Make your changes locally
# ... edit files ...

# 4. Commit and push to staging
git add .
git commit -m "Add new header component"
git push staging feature/new-header

# 5. Test on staging site
# https://mysite-staging.myscalablesite.com

# 6. Merge to main when ready
git checkout main
git merge feature/new-header
git push staging main

What Gets Tracked​

The entire /var/www/html directory is a Git repository, including:

  • WordPress core files
  • Themes (wp-content/themes/)
  • Plugins (wp-content/plugins/)
  • Must-use plugins (wp-content/mu-plugins/)

What's Ignored​

The following are typically in .gitignore:

  • wp-content/uploads/ - Media files (stored separately)
  • wp-config.php - Environment-specific configuration
  • vendor/ - Composer dependencies (regenerated from composer.json)
  • node_modules/ - Node dependencies

Running Git Commands on Staging​

You can run git commands directly on the staging server via SSH. This is useful for checking status, viewing history, or managing branches without pulling locally.

Check Status​

# See uncommitted changes on staging
ssh [email protected] 'git status'

# See what's changed
ssh [email protected] 'git diff'

View History​

# Recent commits
ssh [email protected] 'git log --oneline -10'

# Who changed what
ssh [email protected] 'git log --oneline --author="John" -5'

Branch Management​

# List branches
ssh [email protected] 'git branch -a'

# Switch branches
ssh [email protected] 'git checkout develop'

# Create and switch to new branch
ssh [email protected] 'git checkout -b hotfix/urgent-fix'

Undo Changes​

# Discard uncommitted changes to a file
ssh [email protected] 'git checkout -- wp-content/themes/mytheme/style.css'

# Reset to last commit (discard all uncommitted changes)
ssh [email protected] 'git reset --hard HEAD'
Reset with Care

git reset --hard permanently discards uncommitted changes. Make sure you don't need them!

Interactive Mode​

For multiple git commands, use interactive mode:

wp-shell> git status
wp-shell> git log --oneline -5
wp-shell> git diff wp-content/themes/
wp-shell> exit

Handling Conflicts​

If staging has changes that conflict with your local changes:

# Pull and rebase
git pull staging main --rebase

# Resolve any conflicts, then continue
git add .
git rebase --continue

# Push your changes
git push staging main

Best Practices​

  1. Always pull before pushing - Avoid conflicts by getting the latest changes first
  2. Use feature branches - Keep main stable, test features in branches
  3. Write meaningful commit messages - Makes it easier to track changes
  4. Don't commit sensitive data - Keep credentials in environment variables
  5. Test on staging before production - That's what it's for!
Production Deployments

Changes pushed to staging don't automatically go to production. Use the Deploy feature in your dashboard to promote staging to production.