Deploy code with Git
Updated 27 Nov 2026 deployment git
Pull releases onto your server with a read-only key and a repeatable script.
A read-only deploy key
On the server, as the application user:
ssh-keygen -t ed25519 -f ~/.ssh/deploy -N ''
cat ~/.ssh/deploy.pub
Add the public key to the repository as a read-only deploy key. In ~/.ssh/config:
Host github.com
IdentityFile ~/.ssh/deploy
A deploy script
#!/usr/bin/env bash
set -euo pipefail
cd /srv/app/current
previous=$(git rev-parse HEAD)
git fetch --prune origin
git checkout --detach origin/main
echo "was $previous, now $(git rev-parse HEAD)"
npm ci --omit=dev # or your install step
sudo systemctl restart app
curl -fsS http://127.0.0.1:3000/health
Allow only the restart command in sudo rules.
Roll back
git checkout --detach PREVIOUS_COMMIT
Then rerun the install and restart steps. Database changes may not reverse, so plan migrations carefully.
Do not
Store secrets in the repository, or run the application as root.