Git provides traceable source history, but deploying directly from a developer workstation or an unreviewed branch can make production unpredictable. A safe deployment process identifies the exact commit, verifies the build, protects secrets, and preserves a known rollback point.
Keep production credentials out of Git
Use .gitignore for local environment files, generated uploads, caches, logs, and dependency directories where appropriate. Remember that .gitignore does not remove a file already committed. If a secret enters repository history, rotate it; deleting the latest copy does not make the old credential safe.
Deploy a reviewed revision
A simple server-side workflow may fetch a known branch and check out a reviewed commit:
git fetch origin
git status --short
git checkout --detach <reviewed-commit>
Do not run commands blindly in a live directory. Confirm the repository, working tree, deployment identity, and target commit first. A detached commit is useful for reproducibility, but the release process should record the commit hash and deployment time.
Build and verify dependencies
For Composer applications, use the lock file and production install options appropriate to the project:
composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader
Run this with the intended PHP CLI version and required extensions. Do not run dependency updates on production as part of routine deployment; update dependencies in development, review the lock-file changes, and test them before release.
Separate deployment from runtime
The deployment account should write releases, while the PHP runtime should not be able to modify source code unnecessarily. Keep uploads and generated files in persistent storage. Apply database migrations as a separate controlled step and confirm backward compatibility.
Recovery and audit
Record the commit, migration identifier, and deployment result. Keep the prior release or a reproducible artifact. Test the rollback path periodically. Restrict repository deploy keys and tokens, revoke unused credentials, and avoid storing private keys in the web root. On cPanel, use a supported Git deployment feature or a carefully permissioned deployment script; do not assume that every account has shell access.