Git Basics for Deployment: From clone to post-receive
With git you get history, rollbacks and one-command deploys: a complete guide to a bare repository and a deploy hook on your server.

Table of contents
If you still move your site’s files around over FTP, this article is for you: with git you get history, the ability to roll back, and one-command deploys.
The basics in ten minutes
git init # start tracking the project folder
git status # what has changed
git add . # stage all changes
git commit -m "Update contact page"
git log --oneline # short history
Branches
git switch -c redesign # new branch to experiment on
# ... changes, commits ...
git switch main && git merge redesign
A realistic .gitignore for WordPress
.env
wp-content/uploads/
backup/
*.sql.gz
Passwords and backups have no place in git; these few lines cover the most common slips.
Deploying with a bare repo and a hook
On the server you create a “bare” repository and use a hook to check out every push into the site folder:
# on the server:
git init --bare /var/repo/site.git
cat > /var/repo/site.git/hooks/post-receive <<'EOF'
#!/bin/sh
GIT_WORK_TREE=/var/www/site git checkout -f
EOF
chmod +x /var/repo/site.git/hooks/post-receive
# on your laptop:
git remote add prod ssh://user@server/var/repo/site.git
git push prod main
From now on, “deploy” means git push prod main; every change is in the log, and going back to the previous version is one command. When you outgrow this, a CI pipeline is the next step; see CI/CD with a self-hosted GitHub Actions runner.
Sources
- The official git book: git-scm.com/book
- Hooks documentation: git-scm.com/docs/githooks



Comments
No comments yet. For technical questions, include the details (OS version, the exact error and the command you ran) to get a precise answer.