Loading Kaushal Patel
All articles

How to Deploy a Next.js App on Vercel — Step by Step (with Git Commands)

Deploy Next.js on Vercel — step-by-step guide with Git commands

Vercel is the quickest way to put a Next.js app on the internet: connect a GitHub repository once, and every git push becomes a live deployment — with HTTPS, preview links for every branch and one-click rollbacks. It’s exactly how this website, kaushalpatel.com, is deployed.

In this guide we’ll go from an empty folder to a live site on your own domain, step by step, with every Git command you need along the way.

Diagram: write code on your laptop, push to GitHub, Vercel builds, the site goes live
The whole workflow: commit on your laptop, push to GitHub, Vercel builds, and the site goes live.

What you’ll need

Check your versions in a terminal:

node -v
git --version

If this is your first time using Git on this computer, tell it who you are (this name and email appear on your commits):

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Step 1 — Create your Next.js app

Create a new app called my-app and start the development server:

npx create-next-app@latest my-app --yes
cd my-app
npm run dev

The --yes flag skips the questions and uses the recommended setup: TypeScript, Tailwind CSS, ESLint, the App Router and Turbopack. Open http://localhost:3000 and you’ll see the starter page. Leave the server running while you edit; press Ctrl + C to stop it.

Step 2 — Save your work with Git

create-next-app usually sets up a Git repository and makes a first commit for you. Check:

git status
git log --oneline

If you see “not a git repository”, create one and make the first commit yourself:

git init
git add .
git commit -m "Initial commit"

The generated .gitignore already keeps node_modules, the .next build folder and your .env* secret files out of Git — keep it that way.

Step 3 — Create a GitHub repository and push

On GitHub, create a new repository named my-app. Leave “Add a README”, “.gitignore” and “license” unticked — your project already has these, and an extra commit on GitHub would make your first push fail.

Then connect your local project to it and push:

git remote add origin https://github.com/your-username/my-app.git
git branch -M main
git push -u origin main
Terminal showing git add, git commit, git remote add origin, git branch -M main and git push -u origin main
Your first push: commit, connect the GitHub remote, rename the branch to main, push.

The -u flag links your local main to GitHub’s, so from now on a plain git push is enough.

Step 4 — Import the project into Vercel

  1. Go to vercel.com/new and choose Continue with GitHub.
  2. When asked, install the Vercel GitHub app and give it access to your my-app repository (you can allow just that one repository).
  3. Find my-app in the list and click Import.
  4. Vercel detects Next.js automatically and fills in the build settings — you don’t need to change anything for a standard app.
  5. Click Deploy.

About a minute later your site is live on a .vercel.app address, something like my-app.vercel.app. That’s it — you’ve deployed a Next.js app.

Step 5 — Add environment variables

API keys and other secrets never go into Git. Locally, put them in a .env.local file in the project folder:

# .env.local — never commit this file
DATABASE_URL="your-secret-value"
NEXT_PUBLIC_SITE_NAME="My App"

On Vercel, open your project and go to Settings → Environment Variables. Add each variable and choose where it applies: Production, Preview, Development or all three.

Step 6 — Ship changes with branches and previews

Here’s where Vercel shines. Every branch you push gets its own preview deployment with its own URL, so you can check a change — or send it to a client — before it touches your live site.

# start a new branch for your change
git switch -c feature/new-hero

# …edit your files, then commit and push the branch
git add .
git commit -m "Redesign the hero section"
git push -u origin feature/new-hero

Vercel builds the branch and gives you a preview link. Open a pull request on GitHub (or run gh pr create --fill) and Vercel adds the preview link to it. When you’re happy, merge the pull request: main is your production branch, so the merge deploys to your live site automatically.

Diagram of a feature branch with preview deployments, merged back into main for production
Each push to a branch gets a preview URL; merging into main deploys to production.

Afterwards, bring your local main up to date and tidy up the branch:

git switch main
git pull
git branch -d feature/new-hero

Step 7 — Connect your custom domain

In your project, open Settings → Domains and add your domain, for example example.com. Vercel then shows the DNS records to create at your domain provider. For most setups they look like this:

TypeNameValue
A@76.76.21.21
CNAMEwwwcname.vercel-dns.com
DNS records for pointing a custom domain to Vercel: an A record for @ and a CNAME record for www
Two DNS records connect your domain; Vercel issues the HTTPS certificate for you.

Optional — Deploy from your terminal with the Vercel CLI

The Git workflow above is all most projects need, but the CLI is handy for quick previews and pulling environment variables:

npm i -g vercel        # install the CLI
vercel login           # sign in
vercel link            # connect this folder to your Vercel project
vercel                 # deploy a preview
vercel --prod          # deploy to production
vercel env pull .env.local

Rolling back a bad deploy

Shipped something broken? In the Deployments tab, find the last good production deployment and use Instant Rollback — your site switches back in seconds, without rebuilding. Then fix the problem in Git. If you’d rather undo the change in code, revert the commit and push:

git revert HEAD
git push

Troubleshooting

Your launch checklist

That’s the full path from create-next-app to a live, custom-domain site that redeploys itself whenever you push. If you’d like to see what this setup can grow into, read how I rebuilt this website in Next.js — and if you get stuck deploying your own project, send me a message.

Kaushal Patel

Entrepreneur · Business Owner · IT Consultant — writing about startups, AI and building products.

Keep reading

Related articles