From 0f1426a2d04dac84f35f4e0dfa95219a4701416c Mon Sep 17 00:00:00 2001 From: juanatsap Date: Fri, 31 Oct 2025 12:43:35 +0000 Subject: [PATCH] fix: auto-stash local changes before git pull in deployment - Check for uncommitted changes (both staged and unstaged) - Auto-stash with timestamp before pulling - Prevents "Your local changes would be overwritten" errors - Commented-out option to reapply stash after pull if needed Server changes are preserved in git stash for recovery if needed. Fixes: "error: Your local changes to the following files would be overwritten by merge" --- .github/workflows/deploy.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 32ff84a..7606b87 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,8 +34,20 @@ jobs: echo "🔧 Fixing repository permissions..." sudo chown -R $USER:$USER . + # Stash any local changes before pulling + if ! git diff-files --quiet || ! git diff-index --quiet --cached HEAD; then + echo "💾 Stashing local changes..." + git stash push -m "Auto-stash before deployment $(date +%Y%m%d-%H%M%S)" + fi + git pull origin main + # Reapply stashed changes if any (optional - comment out if not needed) + # if git stash list | grep -q "Auto-stash"; then + # echo "♻️ Reapplying stashed changes..." + # git stash pop || echo "⚠️ Could not reapply stash (conflicts?)" + # fi + echo "🔄 Restarting service..." sudo systemctl restart $SERVICE_NAME