Back to Learning Path

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

  1. Go to github.com/new
  2. Give your repo a name (e.g., "my-first-repo")
  3. Leave it as "Public"
  4. Do NOT check "Add a README" (we already have files)
  5. Click "Create repository"

2. Connect your local repo to GitHub

Copy the URL GitHub gives you, then run:

bash
git remote add origin https://github.com/YOUR-USERNAME/my-first-repo.git

This 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:

bash
git push -u origin main

The -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:

bash
git add .
git commit -m "Describe your changes"
git push

That'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 pull first, then push again.
  • "remote origin already exists" — You've already connected a remote. Check with git remote -v.
  • Branch name mismatch — Some systems use master instead of main. Check with git 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.