The TechTweakers Git Workflow: From Local Branch to Live Deployment
A disciplined version control strategy is the safety net of any full-stack application. Our deployment pipeline is configured so that the main branch acts as the absolute source of truth. The moment code is pushed to main, the production server automatically catches the changes, rebuilds the application, and deploys the updates to the live site.
Because main is directly wired to production, we never write experimental code directly into it. Instead, we use a strict feature-branch workflow.
Here is the standard operating procedure for developing, saving, and deploying new features.
Phase 1: The Sandbox (Creating a Feature Branch)
Before touching a single line of Python or HTML, you must isolate your workspace. A feature branch is an exact clone of your live code where you can build, break, and test without affecting the production site.
How to create a branch:
- Open your terminal in VS Code.
- Ensure you are starting from a clean slate on the main branch:
- PowerShell
git checkout main git pull origin main
- Create and switch to your new feature branch. Use a descriptive naming convention (e.g.,
feature/sponsorship-engineorfix/nav-bar-margin): - PowerShell
git checkout -b feature/your-feature-name
You are now safe to begin coding.
Phase 2: Checkpoints (Staging and Committing)
As you build out the feature, you will generate database migrations, update templates, and modify routes. Rather than relying on terminal commands for every minor save, the VS Code Source Control interface is the most efficient way to track these changes.
How to commit your work:
- Open the Source Control panel on the left sidebar of VS Code (the branching node icon).
- Review the list of modified files under "Changes."
- In the text box, write a concise, descriptive commit message (e.g., Added Quill rich text editor and updated article template).
- Click the Commit button.
Note: If VS Code warns you that there are no "staged" changes and asks if you would like to stage and commit them directly, click Yes. This bundles all your modified files into the save.
- Click the blue Sync Changes (or Publish Branch) button. This pushes your isolated feature branch up to the remote GitHub repository so the code is backed up in the cloud.
Phase 3: Going Live (Merging and Deploying)
Once your local UI is perfect, the database is prepared, and your feature is fully tested, it is time to push the code to production. We do this by bringing the code from your feature branch back into main.
How to execute the production merge:
Execute these three commands in your terminal sequentially:
PowerShell
# 1. Leave your feature branch and return to the main production branch git checkout main # 2. Pull the code from your feature branch into main git merge feature/your-feature-name # 3. Push the updated main branch to the cloud git push origin main
The moment that third command successfully executes, your remote server will automatically pull the updated main branch, build the environment, and take your new features live.
Essential Developer Troubleshooting
The Python REPL Trap
When attempting to run Git merge commands, your terminal may reject them with syntax errors. This almost always occurs because the active terminal has been hijacked by the Python interpreter (REPL).
- The Symptom: Your terminal prompt displays three arrows (
>>>) instead of your standard file path (e.g.,PS C:\Projects\App>). - The Cause: Git commands are shell commands. A terminal stuck in Python cannot understand Git terminology.
- The Fix: Simply type
exit()and press Enter to kill the Python process. Once your standard PowerShell prompt returns, your Git commands will execute perfectly.
Database Migrations
Always remember that Git only tracks code, not database structures. If your feature branch includes new data models or columns, you must execute the necessary SQL queries in your production database interface (e.g., the Supabase SQL Editor) before executing the Phase 3 deployment merge. If the code goes live before the database is ready, the application will throw a 500 Internal Server Error.