GitHub Integration
Your code is only on your computer. What if:
- Computer breaks → code is lost
- Work from different computer → code is trapped
- Share your work → can't access easily
Solution: GitHub - cloud backup for your code.
Time: 20 minutes
What Is GitHub?
GitHub is like Google Drive for code.
Simple explanation:
- Code on computer = local
- Upload to GitHub = cloud backup
- Access anywhere = work from any device
Why this matters:
- Safe backup (computer dies, code survives)
- Work from anywhere (laptop, desktop, phone)
- Professional portfolio (employers check GitHub)
- Collaboration (work with teams)
Step 1: Create Repository on GitHub
Do this on the GitHub website:
- Go to github.com
- Click "New repository" (green button or "+" in top right)
- Fill in:
- Name:
my-project - Description: "My first project" (optional)
- Public (visible to everyone)
- Name:
- Click "Create repository"
GitHub shows you a page with setup commands. Don't worry - Gemini CLI will handle it.
Step 2: Connect Local Code to GitHub
Link your local repository to the GitHub repository.
You ask Gemini CLI: "Connect my local code to GitHub repo https://github.com/username/my-project"
Gemini runs: git remote add origin https://github.com/username/my-project.git
Creates connection between your local Git and GitHub.
Check it worked:
Ask Gemini CLI: "Show me my remote repositories"
Gemini runs: git remote -v
You should see origin pointing to your GitHub URL.
Step 3: Set Up Authentication
GitHub needs to verify it's really you uploading code.
Method: Personal Access Token (recommended for beginners)
Creating Your Token
- Go to github.com → Your profile picture → Settings
- Scroll down → Developer settings
- Personal access tokens → Tokens (classic)
- Click "Generate new token"
- Name it: "My computer"
- Check "repo" (gives access to repositories)
- Click "Generate token"
- Copy the token immediately (starts with
ghp_...)
⚠️ Save it now - you won't see it again!
Where to save: Password manager, secure note file, or write it down safely.
Security notes:
- ⚠️ Never share your token (like a password)
- ⚠️ If exposed, delete it on GitHub immediately
- ✅ Create new tokens for different computers
- ✅ Delete tokens when you stop using a device
Step 4: Push Code to GitHub
Upload your commits to GitHub.
First time push:
You ask Gemini CLI: "Push my code to GitHub for the first time"
Gemini runs: git push -u origin main
GitHub prompts for authentication:
- Username: Your GitHub username
- Password: Paste your token (not your GitHub password!)
Code uploads to GitHub.
Check it worked: Visit github.com/username/my-project - you should see your files and commits.
Subsequent pushes (after first time):
Ask Gemini CLI: "Push my latest commits to GitHub"
Gemini runs: git push
No authentication prompt needed (Git remembers).
Pull: Download from GitHub
Get the latest code from GitHub to your local computer.
You ask Gemini CLI: "Pull the latest code from GitHub"
Gemini runs: git pull
Downloads any changes from GitHub to your local repository.
When to pull:
- Start of work session
- Before making new changes
- Working from different computer
- Someone else pushed changes
Working Across Multiple Computers
First computer (laptop):
- Create code locally
- Commit changes
- Push to GitHub:
git push
Second computer (desktop):
- Clone the repository:
Ask Gemini CLI: "Download my GitHub repo https://github.com/username/my-project"
Gemini runs: git clone https://github.com/username/my-project.git
- Make changes
- Commit
- Push to GitHub:
git push
Back to first computer (laptop):
- Pull from GitHub:
git pull - All desktop changes are now on laptop
- Continue working
The Complete Workflow
Day 1 (Laptop):
→ Write code
→ Commit: git commit -m "Add feature"
→ Push: git push
Day 2 (Desktop):
→ Pull: git pull (get laptop's work)
→ Write more code
→ Commit: git commit -m "Fix bug"
→ Push: git push
Day 3 (Laptop):
→ Pull: git pull (get desktop's work)
→ All changes are here!
No USB drives, no email, no confusion. Your code follows you everywhere.
Key Commands Reference
| Task | Command |
|---|---|
| Connect to GitHub | git remote add origin [URL] |
| Check remote connection | git remote -v |
| First push | git push -u origin main |
| Regular push | git push |
| Pull from GitHub | git pull |
| Clone repository | git clone [URL] |
| Check push status | git status |
Ask Gemini CLI in natural language - you don't need to memorize these.
Troubleshooting Common Issues
"Authentication failed":
- Double-check you're using token (not password)
- Token must have "repo" permission
- Try creating a new token
"Repository not found":
- Check URL spelling
- Repository must exist on GitHub first
- Your GitHub username is correct
"Updates were rejected":
- Someone else pushed first
- Pull first:
git pull - Then push:
git push
Token lost:
- Create a new token on GitHub
- Delete the old one (security)
- Use new token when pushing
Safety Guidelines
Always:
- Push at end of work sessions
- Pull before starting work
- Commit before pushing
- Keep tokens secure
Never:
- Share your tokens
- Commit your token to code
- Use GitHub password for Git commands (use token)
- Force push without understanding consequences
Try With AI
Practice GitHub integration.
Tool: Gemini CLI (or Claude Code, ChatGPT)
Exercise 1: Connect Repository
I created a repository on GitHub: https://github.com/myusername/test-project
Connect my local Git repository to this GitHub repository.
Then verify the connection worked.
Exercise 2: Token Setup
Walk me through creating a Personal Access Token on GitHub.
What permissions do I need?
Where should I save it securely?
Exercise 3: First Push
I have my token ready.
Push my local commits to GitHub for the first time.
Guide me through authentication if GitHub asks.
Then verify my code appears on GitHub.
Exercise 4: Push and Pull Practice
Simulate this workflow:
1. Make a small change locally
2. Commit it
3. Push to GitHub
4. Pull from GitHub (should say "already up to date")
5. Verify everything is in sync
Exercise 5: Clone to New Location
Pretend I'm on a new computer.
How do I download my repository from GitHub?
Walk me through the clone process.
Exercise 6: Troubleshooting
What should I do if:
1. Push says "authentication failed"
2. Push says "rejected - fetch first"
3. I lost my token
Explain each solution.