Git for WordPress Developers: Getting Started
Asad Ali
Founder & Lead Developer · Former WordPress Core Contributor
Git for WordPress Developers: Getting Started
WordPress developers rarely use version control—until they accidentally delete something important. Git prevents that and enables collaboration, history tracking, and safe experimentation.
Why Use Git?
Without Git (typical WordPress):
- Changes are live immediately (scary)
- No history of what changed
- Collaboration via FTP overwriting each other's work
- "backup-final-v2-ACTUAL-final.zip" folders
With Git:
- Every change is tracked
- Full history you can travel through
- Safe experimentation with branches
- Collaboration without conflicts
- Deploy only when ready
Core Concepts
Repository (Repo)
A project folder tracked by Git. Contains your code and its complete history.
Commit
A snapshot of your code at a point in time. Like a save point in a game.
Branch
A parallel version of your code. Make changes without affecting the main code.
Remote
A copy of your repo on a server (GitHub, GitLab). Enables backup and collaboration.
Getting Started
Install Git
Mac:
Already installed, or:
brew install git
Windows:
Download from git-scm.com
Configure Git
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Create a Repository
In your project folder:
cd my-project
git init
This creates a hidden .git folder tracking your project.
Basic Workflow
1. Check Status
git status
Shows:
- Changed files
- New files (untracked)
- Files ready to commit (staged)
2. Stage Changes
Tell Git what to include in the next commit:
Stage specific file
git add index.html
Stage all changed files
git add .
Stage part of a file
git add -p
3. Commit Changes
Save a snapshot with a description:
git commit -m "Add contact form to homepage"
Good commit messages:
- "Fix navigation on mobile"
- "Add blog post listing component"
- "Update footer links"
Bad:
- "Update"
- "Fix bug"
- "Stuff"
4. View History
See commit history
git log
Compact view
git log --oneline
Show last 5 commits
git log -5
Working with Remotes (GitHub)
Create a GitHub Repository
1. Go to github.com
2. Click "New repository"
3. Name it (e.g., "my-website")
4. Don't initialize with README (you have local code)
5. Create repository
Connect Local to Remote
Add remote (copy URL from GitHub)
git remote add origin https://github.com/username/my-website.git
Push to GitHub
git push -u origin main
Push Changes
After committing locally:
git push
Pull Changes
Get changes others pushed:
git pull
Branches
Branches let you work on features without affecting the main code.
Create and Switch Branch
Create and switch in one command
git checkout -b feature/new-header
Or in two commands
git branch feature/new-header
git checkout feature/new-header
Switch Between Branches
git checkout main
git checkout feature/new-header
See All Branches
git branch
Merge a Branch
When your feature is ready:
Switch to main
git checkout main
Merge feature branch
git merge feature/new-header
Delete branch (optional)
git branch -d feature/new-header
Common Scenarios
Undo Changes (Not Committed)
Discard changes to one file
git checkout -- filename.html
Discard all changes
git checkout -- .
Undo Last Commit (Keep Changes)
git reset --soft HEAD~1
View a Past Version
See what a file looked like in a commit
git show abc1234:filename.html
Go back to a commit (just to look)
git checkout abc1234
git checkout main # Return to present
See What Changed
Changes not yet staged
git diff
Changes staged for commit
git diff --staged
Changes between commits
git diff abc1234 def5678
.gitignore
Tell Git to ignore certain files:
.gitignore file
node_modules/
.env
.DS_Store
*.log
dist/
.next/
For WordPress projects:
WordPress .gitignore
wp-content/uploads/
wp-content/upgrade/
wp-content/cache/
wp-config-local.php
*.log
WordPress-Specific Git Tips
What to Track (Theme/Plugin Development)
my-theme/
├── .git/
├── .gitignore
├── style.css
├── functions.php
├── templates/
└── assets/
What NOT to Track
/wp-content/uploads/(media files)
/wp-config.php(contains secrets)
- Entire
/wp-admin/and/wp-includes/
- Cache folders
Using Git with WordPress
Option 1: Theme/Plugin only
Just track your custom code. Most common approach.
Option 2: Full site
Track everything with proper .gitignore.
Option 3: Composer-based
Use Composer to manage WordPress + plugins as dependencies.
GitHub Collaboration
Fork and Pull Request
Contributing to others' projects:
1. Fork - Copy their repo to your GitHub
2. Clone - Download to your computer
3. Branch - Create a feature branch
4. Change - Make your changes
5. Push - Push to your fork
6. Pull Request - Ask them to merge your changes
Pull Requests in Your Own Projects
For team workflows:
1. Create feature branch
2. Push branch to GitHub
3. Open Pull Request
4. Team reviews code
5. Merge when approved
This prevents breaking the main branch.
Modern Workflow with Vercel/Netlify
Git enables magical deployment workflows:
The Flow
1. Push to GitHub
2. Platform detects push
3. Builds your site
4. Deploys to production
Preview Deployments
1. Create a branch
2. Push branch
3. Platform creates preview URL for that branch
4. Test and get feedback
5. Merge to main
6. Production updates automatically
No FTP. No manual deployment. No "did you upload the right file?"
Essential Commands Cheat Sheet
| Command | What It Does |
git init | Create new repository |
git status | Show current state |
git add . | Stage all changes |
git commit -m "message" | Commit staged changes |
git log --oneline | View commit history |
git push | Upload to remote |
git pull | Download from remote |
git checkout -b name | Create and switch branch |
git checkout main | Switch to main branch |
git merge branch | Merge branch into current |
git diff | Show unstaged changes |
git reset --soft HEAD~1 | Undo last commit |
GUI Alternatives
If you prefer visual tools:
- GitHub Desktop - Simple, official GitHub client
- VS Code - Built-in Git support
- GitKraken - Powerful GUI with visualizations
- Sourcetree - Free, feature-rich
Start with command line to understand concepts, then use GUI for convenience.
Next Steps
1. Practice locally - Create a test repo, make commits
2. Create GitHub account - Push your first project
3. Explore GitHub - Fork a project, make a change
4. Connect to deployment - Try Vercel with your repo
FAQ
Q: Can I use Git with WordPress?
Yes, but typically just for themes/plugins. Core WordPress isn't usually tracked.
Q: What if I make a mistake?
Git rarely loses data. You can almost always recover with git reflog.
Q: Do I need GitHub?
No, Git works locally. GitHub (or GitLab, Bitbucket) adds remote backup and collaboration.
Q: How often should I commit?
Often! Commit logical chunks of work. Too many small commits is better than too few giant ones.
Q: How does Git work with deployment?
Modern platforms like Vercel and Netlify automatically deploy when you push to Git. Compare hosting options →
Conclusion
Git transforms how you work:
| Before (WordPress) | After (Git) |
| Changes immediately live | Commit when ready |
| No history | Full change history |
| FTP overwriting | Merge conflicts handled |
| "Is this the right file?" | Definitive source of truth |
| Manual backup zips | Automatic version history |
Every modern development workflow uses Git. Learning it opens doors to better tools, platforms, and practices.
Related guides:
Related Articles
View allTypeScript for JavaScript Developers: A Practical Guide
Learn TypeScript to write safer code. Types, interfaces, and practical patterns that make JavaScript development better.
Tailwind CSS for WordPress Developers: Complete Guide
Learn Tailwind CSS coming from WordPress. Utility-first CSS explained for theme developers making the switch to modern frameworks.
React vs Vue vs Svelte for WordPress Developers
Confused by JavaScript frameworks? This guide explains React, Vue, and Svelte from a WordPress developer's perspective.
Next.js App Router: Ultimate Guide for WordPress Developers
Learn Next.js App Router coming from WordPress. Server components, layouts, data fetching, and building real applications.