GitHub: Push, Pull & Clone
GitHub is where your code lives in the cloud. It's your backup, your portfolio, and how you collaborate with others.
💾
Backup
Your code is safe even if your computer dies
👥
Collaboration
Work with others from anywhere
🌍
Portfolio
Show your work to the world
Local vs Remote
💻
Local Repository
On your computer
- •Where you write code
- •Where you commit changes
- •Works offline
☁️
Remote Repository
On GitHub's servers
- •Backup of your code
- •Shared with others
- •Accessible anywhere
Local push -> <- pull Remote
Step by Step
Create a Remote Repository
Go to github.com and click the + icon in the top right, then select New repository.
On GitHub: Click + -> New repository
- •Give it a name (e.g.,
my-first-repo) - •Choose public or private
- •Do not initialize with README if you have existing code
- •Click "Create repository"
Quick Reference
| Command | What it does |
|---|---|
| git remote -v | List all remotes |
| git remote add origin URL | Add a new remote called "origin" |
| git push -u origin main | Push and set up tracking |
| git push | Push commits to remote |
| git pull | Fetch and merge remote changes |
| git fetch | Download remote changes (don't merge) |
| git clone URL | Copy a remote repo to your computer |
HTTPS vs SSH
HTTPS
https://github.com/user/repo.git
- •Works everywhere
- •Easy to set up
- •May ask for credentials
SSH
git@github.com:user/repo.git
- •No password prompts
- •More secure
- •Requires SSH key setup
Start with HTTPS. Switch to SSH later when you are comfortable.
Best Practices
- • Pull before you push - always get the latest changes first.
- • Commit often, push regularly - small, frequent updates are safer.
- • Write good commit messages - your teammates will thank you.
- • Do not commit sensitive data - passwords, API keys, etc. should stay out of Git.
You now know the basics of connecting local and remote repositories!