- Learn
- Stack Essentials
- Git & GitHub
- Introduction to Git
Understand Git version control basics for managing AI-generated code and collaborating on projects.
Introduction to Git
Git tracks changes to your code, enabling you to undo mistakes, work on features safely, and collaborate with others.
Why Git Matters for AI Development
1. AI Makes Many Changes
AI tools generate significant code changes:
Without Git:
- AI generates code
- Something breaks
- No way to undo
- Start over
With Git:
- AI generates code
- Something breaks
- git checkout . (undo all changes)
- Try again
2. Experiment Safely
Create branches to try new features:
main (stable)
├── feature/new-ui (experimenting)
├── feature/auth (in progress)
└── fix/bug-123 (quick fix)
3. Deploy with Confidence
Git integrates with deployment:
git push → Vercel builds → Site deploys
Core Concepts
Repository (Repo)
A project folder tracked by Git:
my-project/ # Repository
├── .git/ # Git's hidden folder (don't touch)
├── src/
├── package.json
└── README.md
Commit
A snapshot of your code at a point in time:
Commit History:
├── abc123 "Add user authentication"
├── def456 "Fix login bug"
├── ghi789 "Update homepage design"
└── jkl012 "Initial commit"
Branch
A separate line of development:
main ─────●─────●─────●─────●
\ /
feature ───────●─────●───┘
● = commit
Remote
A copy of your repo on GitHub/GitLab:
Local (your computer) ←→ Remote (GitHub)
git push →
← git pull
Essential Commands
Setup
# Configure identity (once)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Initialize new repo
git init
# Clone existing repo
git clone https://github.com/user/repo.git
Daily Workflow
# Check status
git status
# Stage changes
git add . # Add all files
git add src/app/page.tsx # Add specific file
# Commit changes
git commit -m "Add homepage"
# Push to remote
git push
Viewing History
# View commit history
git log
# Compact log
git log --oneline
# View specific file history
git log -- src/app/page.tsx
Understanding Status
git status
Output explained:
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed: # Staged (ready to commit)
modified: src/app/page.tsx
Changes not staged for commit: # Modified but not staged
modified: src/components/Header.tsx
Untracked files: # New files Git doesn't know about
src/components/Footer.tsx
The Git Workflow
1. Make Changes
Edit files with your AI tool or manually.
2. Check Status
git status
# See what changed
3. Stage Changes
git add .
# Or selectively: git add src/specific-file.tsx
4. Commit
git commit -m "Describe what changed"
5. Push
git push
Undoing Changes
Undo Unstaged Changes
# Discard changes to specific file
git checkout -- src/app/page.tsx
# Discard ALL unstaged changes
git checkout .
Undo Staged Changes
# Unstage file (keep changes)
git reset HEAD src/app/page.tsx
# Unstage all (keep changes)
git reset HEAD
Undo Last Commit
# Undo commit, keep changes staged
git reset --soft HEAD~1
# Undo commit, keep changes unstaged
git reset HEAD~1
# Undo commit, discard changes (dangerous!)
git reset --hard HEAD~1
AI Tool Integration
AI Builders (Lovable, Bolt)
These tools often have built-in Git:
Lovable:
Settings → GitHub → Connect Repository
Bolt.new:
Export → GitHub → Creates repo automatically
AI Editors (Cursor, Copilot)
Work directly with local Git:
# In terminal within editor
git add .
git commit -m "AI-generated feature"
git push
Claude Code
Uses Git extensively:
# Claude Code workflow
claude "Add authentication to this app"
# Claude makes changes
git diff # Review changes
git add .
git commit -m "Add authentication (via Claude)"
GitHub Copilot CLI
Use Copilot in your terminal:
# Explain a command
gh copilot explain "git rebase -i HEAD~3"
# Suggest a command
gh copilot suggest "undo last commit but keep changes"
GitHub Copilot Coding Agent
Assign GitHub Issues to Copilot:
# In GitHub Issues, assign to @copilot
# Copilot works asynchronously and creates a PR
# Review and merge when ready
Common Patterns
Start of Day
git pull # Get latest changes
git status # Check local state
End of Feature
git add .
git commit -m "Complete user profile feature"
git push
Quick Fix
git add src/fix.tsx
git commit -m "Fix typo in header"
git push
Experimentation
# Before experimenting
git stash # Save current changes
# Experiment with AI
# ...
# If experiment fails
git checkout . # Discard experiment
# Restore saved changes
git stash pop
.gitignore
Tell Git which files to ignore:
# .gitignore
node_modules/
.env
.env.local
.next/
dist/
*.log
.DS_Store
Best Practices
Commit Messages
# Good
git commit -m "Add user authentication with Supabase"
git commit -m "Fix login redirect bug"
git commit -m "Update homepage hero section"
# Bad
git commit -m "update"
git commit -m "stuff"
git commit -m "wip"
Commit Frequency
Too few commits:
├── "Built entire app"
└── Hard to undo specific changes
Too many commits:
├── "Add button"
├── "Change button color"
├── "Move button"
└── Cluttered history
Just right:
├── "Add user authentication"
├── "Add profile page"
├── "Fix auth redirect issue"
└── Logical, reviewable chunks
Before Pushing
# Check what you're pushing
git status
git diff --staged
# Run tests/build
npm run build
# Then push
git push
Summary
- Repository: Project folder tracked by Git
- Commit: Snapshot of code at a point in time
- Branch: Separate line of development
- Remote: Copy on GitHub
- Essential commands: status, add, commit, push, pull
Next Steps
Learn branching workflows for safe feature development.