Step 1: export and restore MySQL safely
Keep passwords out of the command line: use --password without a value so MySQL prompts for it. Treat dump files as sensitive because they can contain personal and production data.
Export a database
Creates a logical SQL backup while prompting for the database password.
mysqldump --host=<db-host> --user=<db-user> --password <database> > backup.sql
Inspect before importing
Checks that the file is non-empty and lets you review its header before execution.
wc -l backup.sql
head -n 20 backup.sql
Restore a database
Executes the SQL dump against the selected database.
mysql --host=<db-host> --user=<db-user> --password <database> < backup.sql
Step 2: create and inspect tar archives
List unfamiliar archives before extraction. Extract into a dedicated directory so files cannot unexpectedly mix with the current project.
Create a compressed project archive
Archives the current directory while excluding regenerable cache directories.
tar -czf project-backup.tar.gz --exclude='./var/cache' --exclude='./var/page_cache' .
List archive contents
Prints paths stored in a gzip-compressed tar archive without extracting them.
tar -tzf project-backup.tar.gz
Extract to a chosen directory
Extracts the archive into an explicitly selected directory.
tar -xzf project-backup.tar.gz -C <destination-directory>
Step 3: inspect Git changes and commits
These commands are read-only. Use the operating system’s secure credential manager; do not enable plaintext credential storage in shared setup instructions.
Review working-tree state
Shows changed paths, unstaged changes, and staged changes separately.
git status --short
git diff
git diff --staged
Inspect one commit
Displays a commit’s metadata and patch.
git show <commit>
Compare a path between revisions
Limits a revision comparison to the specified file or directory.
git diff <older-commit> <newer-commit> -- <path>
Step 4: run PHP code-quality checks
Install tools as project development dependencies and pin their versions in composer.lock so local and continuous-integration results agree.
Run Magento coding standards
Checks a module against the installed Magento coding-standard rules.
vendor/bin/phpcs --standard=Magento2 <module-path>
Run PHPStan
Performs static analysis at the selected configured rule level.
vendor/bin/phpstan analyse <source-path> --level=<level>
Run Composer validation
Checks composer.json and its lock-file relationship.
composer validate --strict
Step 5: use a focused pre-commit hook
A pre-commit hook should be fast and deterministic. Keep the complete test matrix in continuous integration, where results are shared and enforceable.
Make the hook executable
Allows Git to execute the local pre-commit hook.
chmod +x .git/hooks/pre-commit
Minimal hook pattern
Stops a commit when Composer validation or the project PHPStan command fails.
#!/bin/sh
set -eu
composer validate --strict
vendor/bin/phpstan analyse
Step 6: avoid copied destructive shortcuts
Do not paste broad DELETE statements, disable foreign-key checks, run recursive 777 permissions, or bypass dependency platform requirements. Restore a reviewed local fixture, fix ownership correctly, and resolve runtime compatibility instead.
Preview dependency resolution
Shows the dependency changes Composer would make without modifying installed packages or lock data.
composer update --dry-run
Confirm the target directory
Shows the current path and repository state before a filesystem or database operation.
pwd
git status --short