Step 6: Push to GitHub
You've been saving your work locally with commits. Now let's upload (push) your project to GitHub so it's backed up online and shareable with the world!
Push Your Code Step by Step
1. Create a repository on GitHub
- Go to github.com/new
- Give your repo a name (e.g., "my-first-repo")
- Leave it as "Public"
- Do NOT check "Add a README" (we already have files)
- Click "Create repository"
2. Connect your local repo to GitHub
Copy the URL GitHub gives you, then run:
git remote add origin https://github.com/YOUR-USERNAME/my-first-repo.gitThis tells Git where to upload your code. origin is just a nickname for the remote URL.
3. Push your code!
Upload your commits to GitHub:
git push -u origin mainThe -u flag sets up tracking, so next time you can just type git push.
4. Check GitHub
Refresh your GitHub repository page — your files should now appear there!
The Complete Workflow
From now on, whenever you make changes:
git add .
git commit -m "Describe your changes"
git pushThat's it! Three commands to save and upload your work. You'll type these so often they'll become muscle memory.
Authentication Tip
GitHub may ask you to sign in when you push. If you're asked for a password, you'll need a Personal Access Token instead of your password. Go to GitHub → Settings → Developer Settings → Personal Access Tokens to create one.
Common Mistakes
- "error: failed to push" — This usually means the remote repo has changes you don't have. Try
git pullfirst, then push again. - "remote origin already exists" — You've already connected a remote. Check with
git remote -v. - Branch name mismatch — Some systems use
masterinstead ofmain. Check withgit branch.
Quick Summary
- Create a repo on GitHub first
- Connect with
git remote add origin URL - Push with
git push -u origin main
Congratulations!
You've completed the Git & GitHub basics! You now know how to create repos, track changes, and share your code online. Keep practicing and check out the Cheat Sheet for a quick reference.