Git Workflow
Branch Strategy
Section titled “Branch Strategy”We use a dual-branch strategy to accommodate both Git and FTP workflows:
| Branch | Purpose | Updated By |
|---|---|---|
main | Development team changes | Manual commits |
production | Coworker’s FTP changes | Auto-commits every 15 min |
How It Works
Section titled “How It Works”graph LR A[Coworker FTP] -->|Edits files| B[Production Server] B -->|Auto-commit| C[production branch] C -->|Pull request| D[main branch] E[You - Local Dev] -->|git push| D D -->|make deploy| BFor Development Team
Section titled “For Development Team”- Work on
mainbranch locally - Push changes to GitHub
- Deploy to production with
make deploy
For Coworker (FTP)
Section titled “For Coworker (FTP)”- Edit files via FTP/ShiftEdit
- Cron job auto-commits every 15 minutes
- Changes pushed to
productionbranch - Team reviews via pull request
Daily Workflow
Section titled “Daily Workflow”1. Check for Coworker Changes
Section titled “1. Check for Coworker Changes”# See what coworker changedmake diff
# View recent auto-commitsmake log
# Or open GitHub compare viewmake compare2. Review Changes
Section titled “2. Review Changes”Open GitHub to see detailed changes:
# Open compare view in browseropen "https://github.com/my-marketing-pro/mmp-webapp/compare/main...production"3. Merge if Needed
Section titled “3. Merge if Needed”If coworker made changes you want to keep:
Option A: Via GitHub (Recommended)
- Go to GitHub
- Create pull request:
production→main - Review changes
- Merge pull request
Option B: Via Command Line
# Fetch latest from production branchgit fetch origin production
# Merge into maingit checkout maingit merge origin/production
# Resolve any conflictsgit add .git commit -m "Merge coworker changes from production"git push4. Make Your Changes
Section titled “4. Make Your Changes”# Ensure you're on maingit checkout main
# Make changes# ... edit files ...
# Commitgit add .git commit -m "Your descriptive message"
# Push to GitHubgit push origin main5. Deploy to Production
Section titled “5. Deploy to Production”# Deploy main branch to production servermake deploy
# This runs:# ssh mymarketingpro "cd /var/www/sftp/app &&# sudo git stash &&# sudo git checkout main &&# sudo git pull &&# sudo git stash pop"Auto-Commit System
Section titled “Auto-Commit System”How It Works
Section titled “How It Works”A cron job on the production server runs every 15 minutes:
# Cron schedule*/15 * * * * /usr/local/bin/auto-commit-mmp.sh >> /var/log/auto-commit.log 2>&1Script Location
Section titled “Script Location”File: /usr/local/bin/auto-commit-mmp.sh
#!/bin/bashcd /var/www/sftp/appgit checkout production 2>/dev/nullgit add -Aif ! git diff --staged --quiet; then git commit -m "Auto-commit: $(date '+%Y-%m-%d %H:%M:%S')" git push origin productionfiWhat Gets Committed
Section titled “What Gets Committed”- Any file changes in
/var/www/sftp/app/ - Created by coworker via FTP
- Committed with timestamp:
Auto-commit: 2026-01-21 14:30:00
View Auto-Commit Log
Section titled “View Auto-Commit Log”# SSH into serverssh mymarketingpro
# View logtail -f /var/log/auto-commit.log
# View recent commitscd /var/www/sftp/appgit log --oneline -20Common Commands
Section titled “Common Commands”Check Status
Section titled “Check Status”# Check coworker's changes vs your changesmake diff
# Check production server statusmake status
# View recent auto-commitsmake logPull Latest Code
Section titled “Pull Latest Code”# Pull from main branchmake pull
# Pull from production branch (coworker changes)make syncDeploy
Section titled “Deploy”# Deploy main branch to productionmake deploySSH Access
Section titled “SSH Access”# SSH into production servermake ssh
# Or directlyssh mymarketingproHandling Conflicts
Section titled “Handling Conflicts”Scenario: Coworker Edited Same File
Section titled “Scenario: Coworker Edited Same File”If you and coworker edit the same file:
- Your changes are in
mainbranch - Coworker’s changes are in
productionbranch - Conflict occurs when merging
Resolution:
# Fetch coworker's changesgit fetch origin production
# Try to mergegit merge origin/production
# If conflict:# 1. Open conflicted files# 2. Look for conflict markers:# <<<<<<< HEAD# Your changes# =======# Coworker's changes# >>>>>>> origin/production
# 3. Manually resolve# 4. Stage and commitgit add .git commit -m "Merge production: resolved conflicts"git pushScenario: Need to Rollback
Section titled “Scenario: Need to Rollback”If something breaks after deployment:
# Check recent commitsgit log --oneline -10
# Rollback to previous commitgit reset --hard <commit-hash>
# Force push (careful!)git push origin main --force
# Redeploymake deployGit Configuration
Section titled “Git Configuration”Check Current Branch on Server
Section titled “Check Current Branch on Server”# SSH into serverssh mymarketingpro
# Check branchcd /var/www/sftp/appgit branch --show-currentShould show: main (unless coworker is actively editing via FTP)
Switch Branches on Server
Section titled “Switch Branches on Server”# Switch to main (for deployment)sudo git checkout main
# Switch to production (for FTP access)sudo git checkout productionBest Practices
Section titled “Best Practices”1. Always Pull Before Pushing
Section titled “1. Always Pull Before Pushing”# Before starting workgit pull origin main
# Make changes# ...
# Pushgit push origin main2. Review Auto-Commits Regularly
Section titled “2. Review Auto-Commits Regularly”# Check weeklymake log
# Or open GitHubmake compare3. Coordinate Big Changes
Section titled “3. Coordinate Big Changes”If making major changes, coordinate with coworker:
- Let them know when you’ll deploy
- Ask them to pause FTP edits during deployment
- Review any pending changes first
4. Use Descriptive Commit Messages
Section titled “4. Use Descriptive Commit Messages”# Badgit commit -m "fixes"
# Goodgit commit -m "Fix authentication redirect loop in app-auth.php:23"5. Don’t Force Push to Production Branch
Section titled “5. Don’t Force Push to Production Branch”The production branch is managed by auto-commits. Never:
# DON'T DO THISgit push origin production --forceLet the cron job handle it.
Troubleshooting
Section titled “Troubleshooting”Auto-Commits Stopped
Section titled “Auto-Commits Stopped”# SSH into serverssh mymarketingpro
# Check cron logtail /var/log/auto-commit.log
# Check if script existsls -lh /usr/local/bin/auto-commit-mmp.sh
# Test script manuallysudo /usr/local/bin/auto-commit-mmp.shGit Lock File Error
Section titled “Git Lock File Error”# On serverssh mymarketingprocd /var/www/sftp/app
# Remove lock filesudo rm -f .git/index.lock
# Try againsudo git statusPermission Denied
Section titled “Permission Denied”# On server, check ownershipls -lh /var/www/sftp/app/.git/
# Should be owned by root or www-data# If needed, fix permissions:sudo chown -R www-data:www-data /var/www/sftp/app/.git/GitHub Integration
Section titled “GitHub Integration”Compare Branches
Section titled “Compare Branches”Compare what changed between branches:
https://github.com/my-marketing-pro/mmp-webapp/compare/main...productionCreate Pull Request
Section titled “Create Pull Request”Create PR to merge production → main:
https://github.com/my-marketing-pro/mmp-webapp/pull/new/productionView Auto-Commits
Section titled “View Auto-Commits”See all auto-commits from coworker:
https://github.com/my-marketing-pro/mmp-webapp/commits/productionNext Steps
Section titled “Next Steps”- Development Workflow - Development best practices
- Deployment - Deployment procedures
- Makefile Commands - Quick command reference