Create a repo and push a new project to GitHub

safe beginner #init#first push#new repo#github

When to use this: You have a local folder (like this one) that is not in Git yet, and you want it on GitHub, ready to connect to Vercel.

Before you start

Steps

  1. Turn the folder into a Git repository

    terminal
    git init -b main

    Creates the hidden .git folder and names the first branch main.

    Expected output
    Initialized empty Git repository in C:/Users/Asanka/Documents/GIT/help/.git/
  2. Check what Git sees

    terminal
    git status

    Everything shows as 'untracked'. Make sure node_modules and .env are NOT in this list. If they are, fix .gitignore first.

  3. Stage everything and make the first commit

    terminal
    git add -A
    git commit -m "Initial commit"

    git add -A stages all files (respecting .gitignore). git commit saves the snapshot locally. Nothing is on GitHub yet.

  4. Create the GitHub repo and push (one command)

    terminal
    gh repo create my-site --private --source=. --remote=origin --push

    Creates my-site on your GitHub account, sets it as origin, and pushes main. Replace my-site with your repo name. Use --public if you want it public.

    Prefer the browser? Create an empty repo on github.com (no README), then follow the next step instead.

  5. Or connect an existing empty GitHub repo manually

    terminal
    git remote add origin https://github.com/YOUR-USER/my-site.git
    git push -u origin main

    remote add names the GitHub URL origin. -u links your local main to origin/main, so from now on plain git push and git pull work.

How to verify it worked

  • git remote -v shows origin with your GitHub URL.
  • git status says Your branch is up to date with 'origin/main'.
  • Your files are visible on the repo page on github.com.

How to undo it

Wrong remote URL? Replace it:

terminal
git remote set-url origin https://github.com/YOUR-USER/correct-name.git

Want to un-Git the folder entirely (keeps your files, deletes only history)? Delete the .git folder.

PowerShellGit Bash
Remove-Item -Recurse -Force .gitrm -rf .git

Common errors and fixes

error: src refspec main does not match any You have no commit yet, or your branch is not called main. Run git commit, then git branch -M main.
remote origin already exists Use git remote set-url origin <url> instead of remote add.
failed to push some refs because the GitHub repo was created with a README Pull it first with git pull origin main --allow-unrelated-histories, resolve if asked, then push.
node_modules got committed Add it to .gitignore, run git rm -r --cached node_modules, then commit.

Q&A

What does git push -u origin main do that plain git push does not?

The first push must say where to push. -u (set upstream) remembers origin/main for this branch, so later git push and git pull need no arguments.

Why does git init not put anything on GitHub?

Git is local-first. init and commit only change your PC. GitHub only learns about commits when you push to a remote.

Public or private repo?

Private by default. Vercel can deploy private repos. Make it public only if the code has no secrets and you are happy to share it.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.