Professional code management and deployment workflows.
Git is a distributed version control system that tracks changes in your code over time. It allows you to collaborate with others, revert to previous versions, and maintain different versions of your website simultaneously.
Benefits of Using Git:
Check Git Availability (via SSH):
ssh username@yourserver.com
git --version
# Should output: git version 2.x.xSet Your Identity:
# Configure your name
git config --global user.name "Your Name"
# Configure your email
git config --global user.email "your.email@example.com"
# Verify configuration
git config --listOptional Settings:
# Set default branch name to main
git config --global init.defaultBranch main
# Enable colorful output
git config --global color.ui auto
# Set default editor
git config --global core.editor nano# Navigate to your site
cd ~/public_html
# Initialize Git
git init
# Create .gitignore file
nano .gitignoreRecommended .gitignore for WordPress:
# WordPress specific
wp-config.php
.htaccess
# Cache
/wp-content/cache/
/wp-content/uploads/cache/
# Backups
*.sql
*.tar.gz
*.zip
# Logs
*.log
error_log
debug.log
# OS files
.DS_Store
Thumbs.db
# IDE files
.idea/
.vscode/
*.swp
# Node modules (if using)
node_modules/Add and Commit Files:
# Stage all files
git add .
# Create initial commit
git commit -m "Initial commit: existing website files"
# View commit history
git logSet Up SSH Keys (Recommended):
# Generate SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"
# Display public key (copy to GitHub/GitLab)
cat ~/.ssh/id_ed25519.pubClone Repository:
# Navigate to parent directory
cd ~/
# Clone repository
git clone git@github.com:username/repo-name.git public_htmlDaily Development Cycle:
# 1. Check current status
git status
# 2. Pull latest changes (if working with others)
git pull origin main
# 3. Make your changes (edit files)
# 4. Check what changed
git status
git diff
# 5. Stage changes
git add filename.php
# Or stage all changes
git add .
# 6. Commit changes
git commit -m "Descriptive message about what changed"
# 7. Push to remote repository
git push origin maingit status # Check status
git log # View commit history
git log --oneline # Condensed history
git diff # View changes not staged
git diff --cached # View staged changesgit add filename.php # Stage specific file
git add . # Stage all changes
git add -u # Stage only modified files
git reset filename.php # Unstage file
git commit -m "Message" # Commit staged changesgit checkout -- filename.php # Discard changes
git reset --hard # Discard all uncommitted changes
git reset --soft HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Undo last commit (discard changes)
git revert commit-hash # Revert a specific commitgit remote -v # View remote repositories
git remote add origin git@github.com:... # Add remote
git fetch origin # Fetch changes
git pull origin main # Pull changes
git push origin main # Push changesBranches allow you to test new features without affecting production.
# List branches
git branch
# Create new branch
git branch feature-name
# Switch to branch
git checkout feature-name
# Create and switch in one command
git checkout -b feature-name
# Merge branch into current branch
git merge feature-name
# Delete branch
git branch -d feature-nameCommon Workflow:
# Start new feature
git checkout -b feature/new-contact-form
# Work on feature, commit changes
git add .
git commit -m "Add new contact form"
# Push feature branch
git push origin feature/new-contact-form
# Switch back to main
git checkout main
# Merge feature (after testing)
git merge feature/new-contact-form
# Push to production
git push origin main
# Delete feature branch
git branch -d feature/new-contact-formSimple Manual Deployment:
# On your server via SSH
cd ~/public_html
# Pull latest changes
git pull origin mainAutomated Deployment Script (deploy.sh):
#!/bin/bash
cd ~/public_html
echo "Pulling latest changes..."
git pull origin main
echo "Setting permissions..."
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
echo "Deployment complete!"
dateMake Script Executable:
chmod +x deploy.sh
./deploy.shWhat to Track:
✓ Track:
✗ Don't Track:
When conflicts occur, Git marks the conflicting sections in your files:
<<<<<<< HEAD
Your local changes
=======
Remote changes
>>>>>>> branch-nameResolution Steps:
git statusgit add filenamegit commit