Git Commands Cheatsheet for WordPress Development
A comprehensive reference for Git commands commonly used in WordPress development workflows
Basics
Branches
Remote
WordPress Specific
Workflow
Setup & Configuration
git config –global user.name “Your Name”
Set the name that will be attached to your commits
git config –global user.email “your.email@example.com”
Set the email that will be attached to your commits
git config –list
List all configuration settings
git init
Initialize a new Git repository in the current directory
git clone [url]
Clone a repository from a remote URL
Basic Commands
git status
Show the status of files in the working directory
git add [file]
Add a file to the staging area
git add .
Add all modified and new files to the staging area
git commit -m “Commit message”
Commit staged changes with a message
git log
Show commit history
git diff
Show changes between working directory and staging area
git diff –staged
Show changes between staging area and last commit
Branch Management
git branch
List all local branches
git branch -a
List all local and remote branches
git branch [branch-name]
Create a new branch
git checkout [branch-name]
Switch to a branch
git checkout -b [branch-name]
Create a new branch and switch to it
git merge [branch-name]
Merge a branch into the current branch
git branch -d [branch-name]
Delete a branch
git branch -D [branch-name]
Force delete a branch
Stashing
git stash
Stash changes in a dirty working directory
git stash list
List all stashed changesets
git stash apply
Apply the most recent stash
git stash apply stash@{n}
Apply a specific stash
git stash drop
Remove the most recent stash
git stash pop
Apply and remove the most recent stash
Remote Operations
git remote
List all remote repositories
git remote -v
List all remote repositories with URLs
git remote add [name] [url]
Add a new remote repository
git remote remove [name]
Remove a remote repository
git fetch [remote]
Download objects and refs from a remote
git pull
Fetch and merge changes from remote to current branch
git pull –rebase
Fetch and rebase changes from remote to current branch
git push [remote] [branch]
Push local branch to remote repository
git push -u origin [branch]
Push and set upstream for a branch
git push –tags
Push tags to remote repository
WordPress-Specific Git Strategies
git clone https://github.com/WordPress/WordPress.git
Clone the WordPress core repository
git checkout -b theme-feature
Create a branch for a new theme feature
git checkout -b plugin-bugfix
Create a branch for plugin bug fixes
git add wp-content/themes/your-theme/
Add changes from a specific theme directory
git add wp-content/plugins/your-plugin/
Add changes from a specific plugin directory
WordPress .gitignore Recommendations
# WordPress core (if not managing core with Git)
wp-admin/
wp-includes/
# Configuration files
wp-config.php
.htaccess
# User uploads
wp-content/uploads/
# Cache files
wp-content/cache/
# Logs
*.log
# Plugins (if not managing plugins with Git)
# wp-content/plugins/
# Themes (if not managing themes with Git)
# wp-content/themes/
# Node modules and other build tools
node_modules/
bower_components/
.sass-cache/
Common WordPress .gitignore entries (customize based on your workflow)
Common Development Workflows
Feature Branch Workflow
1.
2. Make changes and test
3.
4.
5.
6. Create Pull Request
7. After review:
git checkout -b feature/name
2. Make changes and test
3.
git add .
4.
git commit -m "Add feature X"
5.
git push -u origin feature/name
6. Create Pull Request
7. After review:
git checkout main && git pull && git merge feature/name
Hotfix Workflow
1.
2.
3. Fix issue and test
4.
5.
6.
7. Create Pull Request
8. After review:
git checkout main
2.
git checkout -b hotfix/issue
3. Fix issue and test
4.
git add .
5.
git commit -m "Fix critical issue X"
6.
git push -u origin hotfix/issue
7. Create Pull Request
8. After review:
git checkout main && git pull && git merge hotfix/issue
Release Workflow
1.
2.
3. Make version changes
4.
5.
6.
7.
8. Create Pull Request
9. After review:
git checkout main
2.
git checkout -b release/1.0.0
3. Make version changes
4.
git add .
5.
git commit -m "Prepare for v1.0.0 release"
6.
git tag -a v1.0.0 -m "Version 1.0.0"
7.
git push origin release/1.0.0 --tags
8. Create Pull Request
9. After review:
git checkout main && git merge release/1.0.0 && git push
Advanced Commands
git rebase [branch]
Reapply commits on top of another branch
git rebase -i HEAD~[n]
Interactive rebase to edit the last n commits
git cherry-pick [commit-hash]
Apply the changes of a specific commit to current branch
git reset –hard [commit]
Reset to a specific commit, discarding all changes
git clean -fd
Remove untracked files and directories
git bisect start
Start a binary search to find which commit introduced a bug
git worktree add [path] [branch]
Add a new working tree associated with the repository
Your competition features discussion could expand with Retro Bowl tournament structures.