Continuous Production Deployments: Pushing Code from VS Code to a Live Linux VPS
How to update a live production Django application when shipping changes from your local editor, including migration handling, asset collection, and zero-error server reloads.
Writing features and resolving bugs on your local development computer is only half the engineering workflow. Shipping those changes to your live virtual private server requires a predictable, repeatable process that prevents downtime, file conflicts, or stale assets.
NOTE: The VPS used here is from interserver.net at a price of $ 3 per month. Click here to purchase, or text us, and we will guide you
1. Committing and Pushing from VS Code
Before moving code to your server, review your local working tree in your VS Code terminal. Ensure you are on the primary branch and all changes are staged cleanly:
git status
git add .
git commit -m "Update service catalog structure and refine user navigation"
git push origin main2. Accessing the Production Environment
Connect to your VPS using your dedicated deploy user account. Navigate to the project directory and activate the virtual environment:
ssh deploy@203.0.113.195
cd ~/Projects/myapp.com
source venv/bin/activate3. Pulling Upstream Commits and Handling Conflicts
Fetch the latest changes from your repository:
git pull origin mainIf you modified tracked files directly on the server and Git blocks your pull, inspect the local diff:
git status
git diffIf the local server modifications were accidental and you want the server to match your remote repository exactly, discard them using:
git checkout .
git pull origin mainNote: Untracked files such as your production .env and user uploaded media folders will remain untouched.
4. Synchronizing Dependencies and Migrations
Whenever an update introduces new packages or changes database schemas, execute the corresponding updates in order:
pip install -r requirements.txt
python manage.py migrate5. Refreshing Static Assets and Restarting Workers
Django templates and stylesheets are compiled by Nginx from the collected static directory, while Python files are held in RAM by running Gunicorn workers. Run both commands to make changes visible to users immediately:
python manage.py collectstatic --no-input
sudo systemctl restart gunicorn6. Creating a One-Line Deployment Script
To eliminate manual typing during routine releases, create a lightweight deployment script inside your project root:
nano deploy.sh#!/usr/bin/env bash
set -e
echo "Pulling latest commits..."
git pull origin main
echo "Installing requirements..."
pip install -r requirements.txt
echo "Running migrations..."
python manage.py migrate
echo "Collecting static assets..."
python manage.py collectstatic --no-input
echo "Reloading Gunicorn workers..."
sudo systemctl restart gunicorn
echo "Deployment complete."Make the script executable:
chmod +x deploy.shFor all subsequent updates, shipping new code from VS Code to production requires running just one command on the server:
./deploy.sh