Web Development courseLesson 19 of 20 · tap to see all lessons
Web Development · Beginner
GitHub Workflow and Deployment: Branches, README, Production Builds, Vercel, and Supabase in Production
Organize team work on GitHub, document your project, build for production, deploy a Next.js and Supabase app, configure the live database, and troubleshoot.
- Qyubie Learn Editorial Team
- Published
- 11 min read
Includes 2 quick checks you can do right here.
An app on localhost only helps you. This lesson puts the class portal on the internet, the way teams do it for real: a clean GitHub workflow, documentation a stranger can follow, a production build, a deployment that updates itself when you push, a production database, and a checklist for when something goes wrong.
By the end of this lesson you will be able to:
- run a team branching workflow with protected
mainand pull requests, - write a README and an
.env.examplefor your project, - build and run your app in production mode, and manage environment variables,
- deploy a Next.js app from GitHub to Vercel,
- set up a production Supabase database and auth URLs, and
- verify a deployment and troubleshoot common failures.
A team workflow on GitHub
Lessons 10 and 14 covered branches and pull requests. A team turns them into rules everyone follows:
mainis always working. Whatever is onmaincan be deployed at any moment, so nobody pushes unfinished work there.- One branch per task, named after it:
feature/student-search,fix/login-error-message,docs/readme-setup. - Every change reaches
mainthrough a pull request, reviewed by at least one teammate. - Small, frequent pull requests beat one giant one at the end. Pull
maininto your branch often to avoid big conflicts. - Clear commit messages in the imperative: "Add delete confirmation", not "changes" or "final version".
GitHub can enforce rule 3. In your repository's Settings, add a branch protection rule (or ruleset) for main that requires a pull request and an approval before merging. Then nobody, including you, can push to main by accident.
Quick check
Documentation: README and .env.example
The README.md in your repository's root is the front page of your project on GitHub. Write it for a classmate who has never seen your app and must run it on their own computer. A solid structure:
# Class Portal
A web app for teachers to manage their class lists: sign up, then add, edit,
and remove students. Each teacher sees only their own records.
**Live site:** https://class-portal.example.com
## Features
- Email and password accounts (Supabase Auth)
- Create, edit, and delete student records with validation
- Responsive layout for phones and laptops
## Tech stack
Next.js 16 (App Router), React, TypeScript, Tailwind CSS, Supabase (PostgreSQL and Auth)
## Getting started
1. Install Node.js 20.9 or newer.
2. Clone the repository and run `npm install`.
3. Create a Supabase project and run `supabase/schema.sql` in its SQL Editor.
4. Copy `.env.example` to `.env.local` and fill in your project's URL and publishable key.
5. Run `npm run dev` and open http://localhost:3000.
## Scripts
- `npm run dev`: development server
- `npm run build`: production build
- `npm start`: run the production build
- `npm test`: unit tests
## Team
- Juan Dela Cruz: database and authentication
- Maria Santos: pages and stylingAlongside it, commit:
.env.example(lesson 17): every variable name, with fake values. Never the real.env.local.supabase/schema.sql: the SQL that creates your tables, constraints, grants, and policies, so anyone can recreate the database. When you change the database, add the change to this file (or a new numbered file such assupabase/002_add_user_id.sql) in the same pull request as the code that needs it.
Building for production
npm run dev is made for development: it rebuilds on every save and shows detailed errors. Users get the production build, which is optimized and much faster. Always try it locally before deploying:
npm run build
npm run startnpm run build compiles everything and checks your TypeScript. If it reports an error, the deployment would fail the same way, so fix it now. npm run start then serves the production build at http://localhost:3000. Click through your test plan (lesson 18) there.
Environment variables in production
The production site needs the same variables as your .env.local, but they're set on the hosting platform, not in a file in Git. Two rules to remember:
NEXT_PUBLIC_values are inlined at build time. After you change one, the app must be built again, which on a hosting platform means redeploying. Server-only variables are read when the server runs.- Production often needs different values than development, such as a different Supabase project (below).
Deploying to Vercel
Next.js apps can be deployed as a Node.js server, a Docker container, a static export, or through adapters for specific platforms. Vercel, the company behind Next.js, connects directly to GitHub and has a free Hobby plan, so it's the easiest starting point. (A Node.js server on your own VPS works too: npm run build, then keep npm run start running with a process manager behind a web server.)
To deploy:
- Push your project to GitHub (lesson 5).
- Sign in to Vercel with your GitHub account.
- Click New Project and select your repository.
- On the configuration page, Vercel detects Next.js. Open Environment Variables and add
NEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYwith your production values. - Click Deploy. Vercel installs your packages, runs
npm run build, and gives you a live address.
From then on, deploying is automatic:
| You... | Vercel creates a... |
|---|---|
push or merge into your production branch (usually main) | production deployment: your live site updates |
| push to any other branch, or open a pull request | preview deployment with its own URL, so teammates can test the change before merging |
Preview deployments make reviews much better: the reviewer clicks a link and tries the feature, instead of only reading code.
To change a variable later, open your project in the Vercel dashboard, select Environment Variables, choose which environments it applies to (Production, Preview, Development), save, and redeploy. Changes never apply to deployments that already exist.
The production database
Use a separate Supabase project
Use one Supabase project for development and a separate project for production. Then testing, sample data, and experiments can never damage real users' data, and you can practice database changes safely before running them on production.
To set up production:
- Create a new Supabase project (for example
class-portal-prod). - Run your
supabase/schema.sqlin its SQL Editor. This is why the schema lives in a file: production gets exactly the same tables, grants, and policies. - Put this project's URL and publishable key in Vercel's Production environment variables.
Never run the "Practice" policies from lesson 16 in production. Before going live, list every policy and read them:
select tablename, policyname, cmd, roles
from pg_policies
where schemaname = 'public'
order by tablename, policyname;Every write policy should be tied to the user (auth.uid()), as in lesson 17. A using ( true ) on insert, update, or delete means anyone can change your data.
Auth URLs in production
Supabase Auth must know your live address, or confirmation emails will send users back to localhost. In the production project's URL Configuration page:
- Set Site URL to your production address, such as
https://class-portal.vercel.app. Email templates use it through{{ .SiteURL }}. - Add your production address to Redirect URLs, for example
https://class-portal.vercel.app/**. - To let preview deployments log in too, Supabase's docs suggest a wildcard such as
https://*-<team-or-account-slug>.vercel.app/**(use your own Vercel slug).
And don't forget the Confirm signup email template change from lesson 17: it's a setting of each Supabase project, so the production project needs it too, and Confirm email should be on.
Quick check
Verifying a deployment
A green "deployed" message only means the build succeeded. Check the live site like a user, with your test plan from lesson 18:
- The home page loads over
https://, with no errors in the DevTools Console. - Sign up with a real email: the confirmation email arrives, and its link opens the live site, not
localhost. - Log in, then create, edit, and delete a record.
- Log in as a second account: the first account's records are invisible.
- Logged out,
/studentsredirects to the login page. - The site works on a real phone.
-
pg_policiesshows no practice policies, and no secret keys appear in the repository.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Build fails on Vercel but works locally | a TypeScript error you didn't build locally, or an import whose capitalization differs from the file name (Windows and macOS ignore case; Vercel's Linux servers don't) | run npm run build locally; match file names exactly |
| The site loads, but data or login fails, mentioning a missing URL or key | environment variables missing in the Production environment | add them in Vercel, then redeploy |
Confirmation emails link to localhost | Site URL still set to localhost | update URL Configuration in the production Supabase project |
| Login works locally but not on the live site | the live address isn't in Redirect URLs | add it |
| Lists are empty in production | the production database has no tables, grants, or policies yet, or RLS hides the rows | run schema.sql; check you're logged in |
"permission denied for table" (42501) | the table has no grant for the role | run the grant from your schema |
| A page shows a server error | an exception in server code | read the deployment's logs in the Vercel dashboard; reproduce with npm run build && npm run start locally |
When a deployment breaks the live site, the fastest safe fix is usually to undo the change: revert the merge on GitHub (with a pull request, as always), and Vercel deploys the previous working version. Then fix the bug calmly on a branch.
Common mistakes
- Committing
.env.localor pasting secret keys into the README. - Skipping the local
npm run buildand finding errors only on Vercel. - Using the development database in production.
- Forgetting to redeploy after changing environment variables.
- Leaving Site URL and Redirect URLs pointing at
localhost. - Leaving practice policies or test accounts in production.
- Pushing directly to
maininstead of using pull requests.
Summary
- Keep
maindeployable: one branch per task, reviewed pull requests, branch protection, clear commits. - Document the project with a README (setup steps, scripts, team),
.env.example, andsupabase/schema.sql. - Run
npm run buildandnpm run startlocally before deploying.NEXT_PUBLIC_values are fixed at build time, so redeploy after changing them. - Vercel deploys from GitHub: production deployments from
main, preview deployments from branches and pull requests. Set environment variables per environment. - Use a separate Supabase project for production, created from
schema.sql, with the correct Site URL, Redirect URLs, and email template, and with only user-based policies. - Verify the live site with your test plan; troubleshoot with the build output, logs, and environment settings; undo bad changes by reverting.
Next: the final full-stack project, where your team builds and deploys an app of your own.