Set Up Git Aliases and Global .gitignore for Faster WordPress Development

Git aliases and a global .gitignore

Two small pieces of Git configuration save time every day: aliases for the commands you type all the time, and a global ignore file for the junk your operating system and editor create in every repository. Both live in your home folder, so they work in every project without touching the project itself.

Problem: Long commands such as git log --oneline --graph --decorate are typed many times a day, and every project’s .gitignore repeats .DS_Store, .idea/ and editor swap files.

Solution: Define aliases with git config --global alias.NAME, and put the OS and editor patterns into a global ignore file referenced by core.excludesFile. Keep project files such as wp-config.php, vendor/ and uploads in the project’s own .gitignore, where the whole team gets them.

Aliases

git config --global alias.s "status -sb"
git config --global alias.co checkout
git config --global alias.sw switch
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.last "log -1 --stat"
git config --global alias.unstage "restore --staged"
git config --global alias.undo "reset --soft HEAD~1"

They end up in ~/.gitconfig:

[alias]
    s = status -sb
    co = checkout
    sw = switch
    lg = log --oneline --graph --decorate --all
    last = log -1 --stat
    unstage = restore --staged
    undo = reset --soft HEAD~1

git undo takes back the last commit but keeps its changes staged, which is handy for a commit made too early. Do not use it on commits that are already pushed. An alias starting with ! runs a shell command: git config --global alias.cleanup '!git branch --merged main | grep -v " main$" | xargs -r git branch -d' deletes local branches that are merged into main.

A global ignore file

git config --global core.excludesFile ~/.gitignore_global
# ~/.gitignore_global: files created by your system and tools
.DS_Store
Thumbs.db
.idea/
*.swp
*~
.vscode/

What belongs in the project instead

# .gitignore of a WordPress project
wp-config.php
.env
/wp-content/uploads/
/wp-content/cache/
/vendor/
/node_modules/
debug.log

These files are ignored because of the project, not because of your laptop. A colleague without your global file would otherwise commit wp-config.php with the database password.

Other useful settings

git config --global push.autoSetupRemote true   # Git 2.37+: first push creates the upstream
git config --global pull.rebase true            # rebase local commits instead of merge commits on pull
git config --global core.autocrlf input         # on macOS and Linux: never commit Windows line endings

NOTE: git config --global --list shows all global settings, and git check-ignore -v path/to/file tells which ignore file and which line ignores a file. More commands: essential Git commands for WordPress developers.