Git & GitHub Basics
Ever lost hours of work because you forgot to save? Or broke something and couldn't remember what it looked like before? Git fixes both problems—and a lot more.
Pro Tip
Git is the industry standard for version control. Even solo developers use it. Once you learn it, you'll wonder how you ever coded without it.
What You'll Learn
By the end of this guide, you'll be able to:
- Track every change to your projects (and undo mistakes)
- Experiment safely with branches
- Push your code to GitHub for backup and collaboration
- Create pull requests for code review
- Use Claude to handle the boring Git stuff
Part 1: Understanding Git
What Problem Does Git Solve?
Without Git, you're one mistake away from disaster. With Git:
| Without Git | With Git |
|---|---|
| "final_v2_REAL_final.docx" | One file, complete history |
| Accidentally delete code, it's gone | Undo any change, any time |
| Can't experiment (might break things) | Branch, experiment, delete if it fails |
| "What changed last week?" | See exactly who changed what, when |
| Collaborating = emailing files | Multiple people work on same codebase |
Key Concepts (Plain English)
| Term | What It Actually Means |
|---|---|
| Repository (repo) | A project folder that Git is tracking |
| Commit | A saved checkpoint of your project |
| Branch | A parallel universe of your code |
| Remote | Your repo on GitHub (in the cloud) |
| Push | Upload your commits to GitHub |
| Pull | Download new commits from GitHub |
Part 2: Your First Repository
Let's create a repo, make changes, and commit them.
- 1
Create a Project
Bashmkdir my-projectcd my-project - 2
Initialize Git
Bashgit initThis creates a hidden
.gitfolder that tracks everything. - 3
Create a File
Bashecho "# My Project" > README.md - 4
Check Status
Bashgit statusYou'll see README.md listed as "untracked"—Git sees it but isn't tracking it yet.
- 5
Stage the File
Bashgit add README.mdStaging means "I want to include this in my next commit."
- 6
Commit
Bashgit commit -m "Initial commit: add README"Congratulations—you've saved your first checkpoint!
Pro Tip
View your history anytime:
git log --onelinePart 3: The Daily Workflow
This is what you'll do every day:
The Commands
# 1. See what changedgit status # 2. Stage your changesgit add . # Stage everything# orgit add specific-file.js # Stage one file # 3. Commit with a messagegit commit -m "feat: add user login" # 4. Push to GitHub (after you've connected—see Part 5)git pushWarning
Always run git status first. It shows you exactly what's about to happen. No surprises.
Part 4: Commit Messages That Don't Suck
Your commit messages are a gift to your future self. Make them useful.
The Format
type: brief description Optional longer explanationTypes
| Type | When to Use |
|---|---|
| feat | New feature |
| fix | Bug fix |
| docs | Documentation changes |
| refactor | Code restructuring (no behavior change) |
| test | Adding or fixing tests |
| chore | Maintenance (dependencies, configs) |
Examples
Good commits:
feat: add password strength indicatorfix: prevent crash when email is emptydocs: add API authentication examplesrefactor: extract validation into separate functionBad commits:
stufffixedwipasdfPro Tip
Let Claude write your commit messages. After making changes, ask:
I changed [describe changes]. Write a commit message.Claude will analyze your git diff and write something better than you would.
Part 5: Connecting to GitHub
GitHub is where your code lives in the cloud. It's your backup, your portfolio, and how you collaborate.
- 1
Create a GitHub Repository
- Go to github.com
- Click + → New repository
- Name it
my-project - Don't check "Initialize with README" (you already have one)
- Click Create repository
- 2
Connect Your Local Repo
GitHub shows you the commands. Run them:
Bashgit remote add origin git@github.com:yourusername/my-project.gitgit branch -M maingit push -u origin main - 3
Verify
Refresh your GitHub page. Your code is there!
From now on, git push sends your commits to GitHub. git pull downloads any new commits.
Part 6: Branches — Parallel Universes
Branches let you experiment without affecting your main code. If your experiment works, merge it. If it fails, delete the branch. No harm done.
Create and Use Branches
# Create a new branch and switch to itgit checkout -b feature/new-thing # Make changes, commit as usualgit add .git commit -m "feat: add new thing" # Push the branch to GitHubgit push -u origin feature/new-thingMerge Back to Main
# Switch to maingit checkout main # Merge your branchgit merge feature/new-thing # Delete the branch (optional, but tidy)git branch -d feature/new-thing # Push the updated maingit pushPro Tip
Branch naming conventions:
feature/user-login— New featuresfix/login-crash— Bug fixesdocs/api-reference— Documentation
Part 7: Pull Requests — Code Review
Instead of merging directly, you can create a pull request (PR) on GitHub. This lets others review your code before it goes into main.
Creating a PR
- Push your branch to GitHub
- Go to your repo on GitHub
- Click Compare & pull request (GitHub often prompts you)
- Fill in the template:
## WhatBrief description of changes ## WhyWhy are these changes needed? ## Changes- Added X- Fixed Y- Updated Z ## TestingHow did you test this?- Click Create pull request
Pro Tip
Let Claude write your PR description:
I'm creating a PR for these changes: [describe]. Write a PR description.Part 8: Easier Ways to Use Git
You don't have to memorize commands. Most developers use visual tools.
Part 9: Common Commands Reference
Everyday Commands
git status # What's changed?git add . # Stage all changesgit commit -m "msg" # Commit with messagegit push # Upload to GitHubgit pull # Download from GitHubViewing History
git log --oneline # Compact historygit diff # See unstaged changesgit diff --staged # See staged changesgit show abc123 # View specific commitBranches
git branch # List branchesgit checkout -b name # Create & switch to branchgit checkout main # Switch to maingit merge name # Merge branch into currentgit branch -d name # Delete branchUndoing Things
git restore file.txt # Discard changes to filegit restore --staged file # Unstage filegit reset HEAD~1 # Undo last commit, keep changesgit reset --hard HEAD~1 # Undo last commit, delete changesWarning
--hard deletes your changes. Use carefully!
Part 10: Troubleshooting
Part 11: .gitignore — What Not to Track
Some files shouldn't be in Git: dependencies, secrets, OS files.
Create .gitignore in your project root:
# Dependenciesnode_modules/venv/__pycache__/ # Secrets.env.env.local*.key # OS files.DS_StoreThumbs.db # Build outputsdist/build/*.logWarning
Never commit secrets! If you accidentally commit a password or API key, consider it compromised. Change it immediately.
Part 12: Using Claude for Git
Claude can handle the tedious parts of Git for you.
Write Commit Messages
I made these changes to auth.ts and api.ts.Analyze my git diff and write a commit message.Resolve Conflicts
I have a merge conflict in this file:[paste the conflicted file]Help me resolve it.Write PR Descriptions
I'm creating a PR with these commits:- abc123: add login form- def456: add validation- ghi789: connect to API Write a PR description.Explain Errors
Git gave me this error:[paste error]What does it mean and how do I fix it?Best Practices Summary
Pro Tip
The golden rules:
- Commit often — Small, focused commits are better than big ones
- Write real messages — "fix login bug" not "asdf"
- Pull before push — Avoid conflicts
- Use branches — Keep main stable
- Review before committing — Always run
git statusfirst
Next Steps
You know Git! Apply it to:
- Data Analysis — Version control your analysis scripts
- App Builder — Manage your app's codebase
- Automation — Track your automation scripts
Resources
- Pro Git Book — Free, comprehensive
- Oh Shit, Git!?! — Fixing mistakes (real solutions, real language)
- GitHub Docs — Official reference