Create a repo and push a new project to 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
-
Turn the folder into a Git repository
terminalgit init -b mainCreates the hidden
.gitfolder and names the first branchmain.Expected output
Initialized empty Git repository in C:/Users/Asanka/Documents/GIT/help/.git/
-
Check what Git sees
terminalgit statusEverything shows as 'untracked'. Make sure
node_modulesand.envare NOT in this list. If they are, fix.gitignorefirst. -
Stage everything and make the first commit
terminalgit add -A git commit -m "Initial commit"git add -Astages all files (respecting.gitignore).git commitsaves the snapshot locally. Nothing is on GitHub yet. -
Create the GitHub repo and push (one command)
terminalgh repo create my-site --private --source=. --remote=origin --pushCreates
my-siteon your GitHub account, sets it asorigin, and pushesmain. Replacemy-sitewith your repo name. Use--publicif you want it public.Prefer the browser? Create an empty repo on github.com (no README), then follow the next step instead.
-
Or connect an existing empty GitHub repo manually
terminalgit remote add origin https://github.com/YOUR-USER/my-site.git git push -u origin mainremote addnames the GitHub URLorigin.-ulinks your localmaintoorigin/main, so from now on plaingit pushandgit pullwork.
How to verify it worked
git remote -vshowsoriginwith your GitHub URL.git statussaysYour 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:
git remote set-url origin https://github.com/YOUR-USER/correct-name.gitWant to un-Git the folder entirely (keeps your files, deletes only history)? Delete the .git folder.
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.