Manage Git sync between VPS and GitHub for Hostinger srv759970. Handles unrelated histories, untracked files, diverged branches, and sync conflicts automatically.
Automates Git sync between Hostinger VPS and GitHub for the incluzhact repository. Handles unrelated histories, untracked files, diverged branches, and merge conflicts. Used when git pull fails or before deployments to ensure VPS matches GitHub exactly.
/plugin marketplace add theflysurfer/claude-skills-marketplace/plugin install theflysurfer-claude-skills-marketplace@theflysurfer/claude-skills-marketplaceThis skill is limited to using the following tools:
Automate Git synchronization between VPS and GitHub, handling common edge cases that occur during deployments.
/var/www/incluzhactInvoke automatically when:
Problem: VPS has independent commit history from GitHub
fatal: refusing to merge unrelated histories
Solutions:
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
git fetch origin main
git merge origin/main --allow-unrelated-histories -m "Merge GitHub into VPS"
EOF
Use when: VPS has important changes to keep
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
git fetch origin main
git reset --hard origin/main
EOF
Use when: VPS should exactly match GitHub (most common)
⚠️ Always verify user intent before hard reset
Problem: Files like CLAUDE.md, claude.md, nul block checkout/merge
error: The following untracked working tree files would be overwritten by checkout:
CLAUDE.md
Please move or remove them before you switch branches.
Solution: Clean untracked files
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
# List untracked files first (safety check)
echo "Untracked files to remove:"
git status --porcelain | grep '^??'
# Remove untracked files
git clean -fd
# Or remove specific files
rm -f CLAUDE.md claude.md nul
EOF
Safety: Always list files before cleaning
Problem: VPS and GitHub histories have diverged
Your branch and 'origin/main' have diverged,
and have 5 and 10 different commits each, respectively.
Diagnosis:
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
# Show divergence
git log --oneline --graph --all --decorate -20
# Count commits ahead/behind
git rev-list --count origin/main..HEAD # VPS ahead
git rev-list --count HEAD..origin/main # VPS behind
EOF
Solutions:
# Rebase VPS commits onto GitHub (rewrites history)
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git rebase origin/main'
# Or merge (preserves history)
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git merge origin/main'
# Simple fast-forward pull
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git pull origin main'
# Hard reset to match GitHub (safest for deployments)
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
git fetch origin main
git reset --hard origin/main
EOF
Problem: Conflicting changes between VPS and GitHub
Diagnosis:
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
# List conflicted files
git diff --name-only --diff-filter=U
# Show conflict details
git status
EOF
Solutions:
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
git merge --abort
git reset --hard origin/main
EOF
# 1. Identify conflicts
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git diff --name-only --diff-filter=U'
# 2. Read conflicted files
ssh automation@69.62.108.82 'cd /var/www/incluzhact && cat path/to/conflicted/file.ts'
# 3. Resolve manually or abort
Complete workflow for safe VPS sync before deployment:
# Step 1: Check current VPS state
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
echo "=== Current branch ==="
git branch --show-current
echo "=== Status ==="
git status --short
echo "=== Last 5 commits ==="
git log --oneline -5
echo "=== Remote comparison ==="
git fetch origin
git log --oneline HEAD..origin/$(git branch --show-current) | wc -l || echo "Up to date"
EOF
# Step 2: Clean untracked files (if any)
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
if [ -n "$(git status --porcelain | grep '^??')" ]; then
echo "Cleaning untracked files..."
git clean -fd
fi
EOF
# Step 3: Sync with GitHub (choose method)
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
BRANCH=$(git branch --show-current)
# Method A: Normal pull (works if no divergence)
if git pull origin $BRANCH 2>&1 | grep -q "fatal\|error"; then
echo "Pull failed, using hard reset..."
git fetch origin $BRANCH
git reset --hard origin/$BRANCH
else
echo "Pull successful"
fi
EOF
# Step 4: Verify sync
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
echo "=== Sync verification ==="
git log --oneline -3
git status
EOF
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
BRANCH=$(git branch --show-current)
git clean -fd
git fetch origin $BRANCH
git reset --hard origin/$BRANCH
echo "VPS now matches GitHub $BRANCH"
EOF
ssh automation@69.62.108.82 << 'EOF'
cd /var/www/incluzhact
git fetch origin
BRANCH=$(git branch --show-current)
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/$BRANCH)
if [ "$LOCAL" = "$REMOTE" ]; then
echo "✅ VPS is up to date"
else
echo "⚠️ VPS needs sync"
echo "Local: $LOCAL"
echo "Remote: $REMOTE"
fi
EOF
BRANCH="staging" # or "main"
ssh automation@69.62.108.82 << EOF
cd /var/www/incluzhact
# Clean workspace
git clean -fd
git reset --hard
# Switch branch
git checkout $BRANCH
git pull origin $BRANCH
echo "Switched to $BRANCH"
git log --oneline -3
EOF
Before any destructive operation (hard reset, clean):
Verify current state:
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git status'
Check for uncommitted changes:
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git diff --stat'
Ask user if unsure:
# Use AskUserQuestion tool if VPS has diverged commits
Verify after sync:
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git log --oneline -5'
# Check SSH connection
ssh automation@69.62.108.82 'whoami'
# Check Git repo ownership
ssh automation@69.62.108.82 'ls -la /var/www/incluzhact/.git'
# Fix ownership if needed
ssh automation@69.62.108.82 'sudo chown -R automation:automation /var/www/incluzhact'
# Verify repo exists
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git status'
# Re-initialize if needed (DANGEROUS)
ssh automation@69.62.108.82 << 'EOF'
cd /var/www
rm -rf incluzhact
git clone https://github.com/theflysurfer/Site-web-Clem-2.git incluzhact
cd incluzhact
git checkout staging # or main
EOF
# Check VPS internet connection
ssh automation@69.62.108.82 'ping -c 3 github.com'
# Check DNS
ssh automation@69.62.108.82 'cat /etc/resolv.conf'
Use this skill before building and restarting PM2:
# 1. Sync Git (this skill)
bash git-vps-sync workflow
# 2. Install dependencies
ssh automation@69.62.108.82 'cd /var/www/incluzhact && npm install'
# 3. Build
ssh automation@69.62.108.82 'cd /var/www/incluzhact && npm run build'
# 4. Restart PM2
ssh automation@69.62.108.82 'pm2 restart incluzhact'
| Scenario | Recommended Action | Risk |
|---|---|---|
| VPS behind GitHub | git pull | Low |
| Untracked files | git clean -fd | Medium |
| Diverged histories | git reset --hard origin/branch | High |
| VPS has unique commits | Ask user, then merge or reset | High |
| Merge conflict | Abort + reset | Medium |
git fetch origingit status before destructive opsgit cleangit log --oneline -3automation@69.62.108.82/var/www/incluzhactorigin pointing to https://github.com/theflysurfer/Site-web-Clem-2.gitmain (production) or staging (preview)git clean -fd)origin/[branch] exactlyObligatoires:
Optionnels:
Bash (usage: SSH commands, git fetch/reset/clean operations, git status verification)Read (usage: verify ecosystem.config.cjs or deployment config exists)AskUserQuestion (usage: confirm hard reset if VPS has diverged commits that may need preservation)User: git push origin staging (on local machine)
↓
[Optional] julien-infra-hostinger-ssh (verify SSH access)
↓
julien-infra-git-vps-sync (THIS SKILL)
├─► SSH to VPS
├─► cd /var/www/incluzhact
├─► git clean -fd (remove untracked files)
├─► git fetch origin [branch]
├─► git reset --hard origin/[branch]
└─► Verify sync: git log --oneline -3
↓
VPS Git repository now matches GitHub
↓
[Next: julien-infra-hostinger-deployment]
├─► npm install
├─► npm run build
├─► pm2 restart incluzhact-preview
└─► (continues deployment workflow)
Scenario: After pushing code to GitHub staging, VPS has unrelated histories error during deployment
Command:
# Invoked automatically by deployment skill, or manually:
# "Sync VPS Git repository with GitHub staging branch"
Result:
/var/www/incluzhact reset to match origin/staging# Safe sync (try pull, fallback to reset)
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git pull || (git fetch && git reset --hard origin/$(git branch --show-current))'
# Nuclear option (match GitHub exactly)
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git clean -fd && git fetch origin && git reset --hard origin/$(git branch --show-current)'
# Check if sync needed
ssh automation@69.62.108.82 'cd /var/www/incluzhact && git fetch && git status'
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.