Beginner Friendly

How to Add Existing Code to GitHub

You already built your project on your computer. This guide shows exactly how to upload it to GitHub with clean, copy-paste commands anyone can follow.

Developer workspace for Git and GitHub

Step 1: Create GitHub Repo

  1. Open GitHub and click New repository.
  2. Give your repository a name.
  3. Create it as an empty repository.
  4. Do not add README or .gitignore if your local project already has files.

Step 2: First Local Commit

Open terminal inside your project folder and run:

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

Step 3: Connect Remote

Replace YOUR_USERNAME and YOUR_REPO_NAME:

HTTPS remote
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
git remote -v
SSH remote
git remote add origin git@github.com:YOUR_USERNAME/YOUR_REPO_NAME.git
git remote -v

Step 4: Push Code to GitHub

First push
git branch -M main
git push -u origin main

For your next updates use:

Daily workflow
git add .
git commit -m "Describe what you changed"
git push

Common Errors and Fixes

remote origin already exists
git remote remove origin
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
rejected push because remote has commits
git pull origin main --rebase
git push
Code editor and terminal for GitHub setup

Before You Push, Check These

Do not push secrets like .env, API keys, or private tokens.
Add private files to .gitignore before your first push.
Run your app once and ensure everything works.

Frequently Asked Questions

How do I upload an existing project to GitHub?

Initialize Git in your local folder, commit your files, set remote origin, then push to your main branch.

What if remote origin already exists?

Remove old remote using git remote remove origin and add the new one using your GitHub repo URL.

Can I push .env to GitHub?

No. Keep secrets out of Git. Add .env in .gitignore before you push.