saulnyongesa4@gmail.com | +254708560861
Blog Post

Continuous Production Deployments: Pushing Code from VS Code to a Live Linux VPS

Published Oct 25, 2026

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.

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 main

2. 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/activate

3. Pulling Upstream Commits and Handling Conflicts

Fetch the latest changes from your repository:

git pull origin main

If you modified tracked files directly on the server and Git blocks your pull, inspect the local diff:

git status
git diff

If 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 main

Note: 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 migrate

5. 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 gunicorn

6. 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.sh

For all subsequent updates, shipping new code from VS Code to production requires running just one command on the server:

./deploy.sh
Back to All Blog Posts Home Overview