Git & GitHub Basics
Master version control and collaboration with Git and GitHub.
What You'll Learn
- Core Git concepts (repos, commits, branches)
- Commit best practices
- Branching and merging
- Pushing to GitHub
- Pull requests and code review
- Using Claude for Git workflows
Prerequisites
- Completed Start Here setup
- Git and GitHub configured
Git Core Concepts
What is Git?
Git is a version control system that tracks changes to your files over time. Think of it as "Track Changes" for code, but much more powerful.
Key Terms
- Repository (repo): A project tracked by Git
- Commit: A snapshot of your project at a point in time
- Branch: A parallel version of your project
- Remote: A version of your repo hosted elsewhere (like GitHub)
- Clone: Download a copy of a remote repo
- Push: Send your commits to a remote
- Pull: Get commits from a remote
Your First Repository
Initialize a New Repo
# Create a project foldermkdir my-projectcd my-project # Initialize Gitgit init # Create a READMEecho "# My Project" > README.md # Check statusgit statusYou'll see README.md is "untracked".
Make Your First Commit
# Stage the filegit add README.md # Commit with a messagegit commit -m "Initial commit: Add README" # View historygit logBest Practice: Commit messages should be clear and descriptive.
Commit Best Practices
Good Commit Messages
Use the format:
type: brief description Optional detailed explanationTypes:
feat:New featurefix:Bug fixdocs:Documentationrefactor:Code restructuringtest:Adding testschore:Maintenance
Examples:
Good:
feat: add user authenticationfix: resolve login redirect loopdocs: update installation guideBad:
stufffixedwipasdfUsing Claude for Commit Messages
Ask Claude:
I changed [describe changes]. Write a good commit message.Claude can analyze your git diff and suggest a message!
Working with Branches
Why Branches?
Branches let you work on features without affecting the main code.
Create and Switch Branches
# Create a new branchgit branch feature/new-feature # Switch to itgit checkout feature/new-feature # OR do both at oncegit checkout -b feature/new-feature # List branchesgit branch # See current branchgit branch --show-currentMerge a Branch
# Switch to maingit checkout main # Merge your featuregit merge feature/new-feature # Delete the branch (optional)git branch -d feature/new-featureEasier Ways to Use Git & GitHub
Terminal vs GUI Tools
You don't have to use terminal commands! Many developers find visual tools easier, especially when starting out.
GitHub Website (Easiest for Beginners)
What you can do directly on GitHub.com:
- Create and edit files - Click "Add file" → "Create new file"
- Upload files - Drag and drop files directly into browser
- Edit existing files - Click any file → pencil icon to edit
- Commit changes - GitHub auto-commits when you save
- Create branches - Dropdown at top left
- Review changes - Visual diff view shows what changed
- Merge pull requests - Click "Merge pull request" button
- Manage collaborators - Settings → Collaborators
- View history - Click "commits" to see all changes
Perfect for:
- Quick fixes and typos
- Editing documentation
- Learning Git concepts visually
- Small projects
- Non-technical team members
Example: Edit a file on GitHub
- Navigate to your file on github.com
- Click the pencil icon (top right)
- Make your changes
- Scroll down, add commit message
- Click "Commit changes" - Done!
VS Code Integration (Best for Developers)
VS Code has Git built-in! No terminal needed.
Setup VS Code Git
- Install VS Code: code.visualstudio.com
- Open your project: File → Open Folder
- Source Control Panel: Click icon on left (looks like branching diagram)
Using Git in VS Code
Make commits:
- See changed files in Source Control panel
- Hover over file → click "+" to stage
- Type commit message at top
- Click checkmark to commit
Push to GitHub:
- Click "..." menu in Source Control
- Select "Push"
- Done!
Create branches:
- Click branch name in bottom-left corner
- "Create new branch"
- Enter name
- Start coding!
Merge changes:
- Switch to target branch (bottom-left)
- Click "..." → "Branch" → "Merge Branch"
- Select branch to merge
- Resolve any conflicts in visual editor
View history:
- Install "GitLens" extension (highly recommended!)
- See who changed what, when, and why
- Visual commit history
- Inline blame annotations
Why VS Code is great:
- See all changes visually
- Stage individual lines (not just files!)
- Syntax highlighting in diffs
- Integrated with your coding workflow
- Extensions like GitLens add superpowers
- Preview changes before committing
- Built-in merge conflict resolver
GitHub Desktop (Easiest Desktop App)
Download: desktop.github.com
Features:
- Visual commit interface
- Drag-and-drop files to stage
- Branch switcher with visual diagram
- One-click push/pull
- Conflict resolution wizard
- Works offline
Perfect for: Anyone who prefers GUI over terminal, beginners, designers, project managers.
Workflow:
- Open GitHub Desktop
- Select your repository
- See changes in left panel
- Check boxes to stage files
- Write commit message at bottom
- Click "Commit to main"
- Click "Push origin" - Done!
Other GUI Tools
GitKraken (Most Visual)
- gitkraken.com
- Beautiful graph of branches
- Drag-and-drop branch merging
- Interactive rebase
- Free for public repos
Sourcetree (Free & Powerful)
- sourcetreeapp.com
- Advanced features in simple UI
- Good for large repositories
- Windows and Mac
Tower (Professional)
- git-tower.com
- Undo almost anything
- Pull request management
- Paid but very polished
VS Code + Claude = Magic
Use Claude Code directly in VS Code!
- Install Claude Code: docs.claude.com/claude-code
- Open terminal in VS Code: Ctrl+` (or View → Terminal)
- Ask Claude to handle Git:
BashClaude, commit my changes with a good messageClaude, create a new branch for this featureClaude, help me resolve this merge conflict
Claude can:
- Write commit messages by analyzing your changes
- Create and manage branches
- Resolve merge conflicts
- Write PR descriptions
- Explain git errors
- Suggest workflow improvements
Example conversation:
You: "I made changes to 3 files, help me commit them" Claude: [Analyzes changes]- auth.ts: Added password validation- api.ts: Fixed rate limiting bug- README.md: Updated installation steps Suggested commits:1. "fix: implement password strength validation"2. "fix: resolve rate limiting edge case"3. "docs: clarify installation requirements" Shall I create these commits?Recommended Setup for Beginners
Start simple, add complexity as needed:
-
Week 1: Use GitHub website only
- Create repos, edit files, make commits
- Learn concepts visually
-
Week 2: Add GitHub Desktop
- Clone repos locally
- Make bigger changes offline
- Practice branches
-
Week 3: Switch to VS Code Git
- Integrate with coding workflow
- Install GitLens extension
- Learn staging individual lines
-
Week 4: Learn terminal basics
- Use Claude to help with commands
- Keep GUI as backup
- Mix and match tools
You can use all these tools on the same repository! Edit on GitHub, commit in VS Code, push with GitHub Desktop - whatever feels easiest.
Integrating with Other Apps
Notion:
- Link GitHub issues in Notion databases
- Embed GitHub widgets
- Use Notion API to create issues
Slack:
- Install GitHub app for Slack
- Get notified of commits, PRs, issues
/github subscribe owner/repoto follow repos
Jira:
- Link commits to Jira tickets
- Use commit message format:
"ABC-123: add feature" - Auto-update Jira status from commits
Linear:
- Similar to Jira integration
- Cleaner UI, better GitHub sync
Figma:
- Link designs to GitHub issues
- Add Figma links in PR descriptions
- Track implementation status
Discord:
- GitHub webhook notifications
- Show commits in dev channel
- Community involvement tracking
Connecting to GitHub
Create a GitHub Repository
- Go to github.com
- Click "+" → "New repository"
- Name:
my-project - Don't initialize with README (you already have one)
- Click "Create repository"
Connect Your Local Repo
# Add GitHub as remotegit remote add origin git@github.com:yourusername/my-project.git # Push your codegit push -u origin main # View remotesgit remote -vDaily Git Workflow
The Basic Cycle
# 1. Check what changedgit status # 2. Stage filesgit add file1.txt file2.txt# Or stage everythinggit add . # 3. Commitgit commit -m "feat: add new features" # 4. Push to GitHubgit pushPull Before You Push
# Get latest changes from GitHubgit pull # Then make your changes and pushgit add .git commit -m "your message"git pushWorking with Claude on Git
Ask Claude to Plan Commits
I made these changes:[describe changes] How should I organize these into commits?Get Help with Conflicts
If you have merge conflicts:
I have a merge conflict in [file]. Here's the content:[paste conflict markers] Help me resolve it.Review Before Committing
Here's my git diff:[paste diff] Review the changes and suggest a commit message.Pull Requests
What is a Pull Request?
A pull request (PR) asks to merge your branch into another branch (usually main).
Creating a PR
-
Push your branch to GitHub:
Bashgit push -u origin feature/my-feature -
Go to your repo on GitHub
-
Click "Compare & pull request"
-
Add title and description:
Markdown## What[Brief description]## Why[Reason for changes]## Changes- [Change 1]- [Change 2]## Testing- [How you tested] -
Click "Create pull request"
Using Claude for PR Descriptions
I'm creating a PR for these changes:[describe changes] Write a good PR description.Common Git Commands
Status and Info
git status # See what changedgit log # View commit historygit log --oneline # Compact historygit diff # See unstaged changesgit diff --staged # See staged changesgit show COMMIT_ID # View a specific commitStaging and Committing
git add FILE # Stage specific filegit add . # Stage all changesgit commit -m "message" # Commit with messagegit commit --amend # Fix last commitBranches
git branch # List branchesgit branch NAME # Create branchgit checkout NAME # Switch branchgit checkout -b NAME # Create and switchgit merge NAME # Merge branchgit branch -d NAME # Delete branchRemote Operations
git clone URL # Clone repositorygit remote -v # List remotesgit push # Push to remotegit pull # Pull from remotegit fetch # Get remote changes (don't merge)Undo Changes
git restore FILE # Discard changes to filegit restore --staged FILE # Unstage filegit reset HEAD~1 # Undo last commit (keep changes)git reset --hard HEAD~1 # Undo last commit (delete changes!)Git Ignore
.gitignore tells Git which files to ignore.
Common Patterns
# Node.jsnode_modules/npm-debug.log # Python__pycache__/*.pycvenv/ # OS.DS_StoreThumbs.db # IDE.vscode/.idea/ # Environment.env.env.local # Build outputsdist/build/*.logTroubleshooting
Forgot to Pull Before Committing
git pull --rebase# Resolve any conflictsgit pushWant to Undo Last Commit
# Keep changes, undo commitgit reset HEAD~1 # Delete changes and commitgit reset --hard HEAD~1Committed to Wrong Branch
# Note the commit IDgit log # Switch to correct branchgit checkout correct-branch # Cherry-pick the commitgit cherry-pick COMMIT_ID # Go back and remove from wrong branchgit checkout wrong-branchgit reset --hard HEAD~1Merge Conflicts
# Pull causes conflictsgit pull # Fix conflicts in files (look for <<<<<<, ======, >>>>>>)# Then:git add .git commit -m "Resolve merge conflicts"git pushBest Practices
Commit Often
- Small, focused commits are better than large ones
- Commit complete, working changes
- Don't commit broken code
Write Good Messages
- Clear, concise, descriptive
- Explain why, not just what
- Follow conventional commits
Use Branches
mainshould always work- Create branches for features and fixes
- Delete branches after merging
Pull Before Push
- Always
git pullbefore starting work - Reduces merge conflicts
- Keeps you in sync with team
Review Before Committing
git diff # See what you changedgit status # Confirm what you're committingWorking with Teams
Collaboration Workflow
-
Clone the repo:
Bashgit clone git@github.com:team/project.git -
Create branch for your work:
Bashgit checkout -b feature/my-work -
Make changes and commit:
Bashgit add .git commit -m "feat: add feature" -
Push branch:
Bashgit push -u origin feature/my-work -
Create PR on GitHub
-
Code review with team
-
Merge PR after approval
-
Pull main and repeat:
Bashgit checkout maingit pull
Next Steps
You now know Git basics! Apply this knowledge:
- Track your data analysis projects: Data Analysis
- Version control your apps: App Builder
- Manage automation scripts: Automation
Additional Resources
- Pro Git Book (free)
- GitHub Docs
- Git Cheat Sheet
- Oh Shit, Git!?! (fixing mistakes)
Practice makes perfect! The best way to learn Git is to use it daily.