Skip to main content

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.

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
The Git Mental Model
Think of Git as checkpoints in a video game

Part 1: Understanding Git

What Problem Does Git Solve?

Without Git, you're one mistake away from disaster. With Git:

Without GitWith Git
"final_v2_REAL_final.docx"One file, complete history
Accidentally delete code, it's goneUndo 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 filesMultiple people work on same codebase

Key Concepts (Plain English)

Git Vocabulary
TermWhat It Actually Means
Repository (repo)A project folder that Git is tracking
CommitA saved checkpoint of your project
BranchA parallel universe of your code
RemoteYour repo on GitHub (in the cloud)
PushUpload your commits to GitHub
PullDownload new commits from GitHub

Part 2: Your First Repository

Let's create a repo, make changes, and commit them.

  1. 1

    Create a Project

    Bash
    mkdir my-project
    cd my-project
  2. 2

    Initialize Git

    Bash
    git init

    This creates a hidden .git folder that tracks everything.

  3. 3

    Create a File

    Bash
    echo "# My Project" > README.md
  4. 4

    Check Status

    Bash
    git status

    You'll see README.md listed as "untracked"—Git sees it but isn't tracking it yet.

  5. 5

    Stage the File

    Bash
    git add README.md

    Staging means "I want to include this in my next commit."

  6. 6

    Commit

    Bash
    git commit -m "Initial commit: add README"

    Congratulations—you've saved your first checkpoint!


Part 3: The Daily Workflow

This is what you'll do every day:

Daily Git Cycle
Rinse and repeat

The Commands

Bash
# 1. See what changed
git status
# 2. Stage your changes
git add . # Stage everything
# or
git add specific-file.js # Stage one file
# 3. Commit with a message
git commit -m "feat: add user login"
# 4. Push to GitHub (after you've connected—see Part 5)
git push

Part 4: Commit Messages That Don't Suck

Your commit messages are a gift to your future self. Make them useful.

The Format

Bash
type: brief description
Optional longer explanation

Types

TypeWhen to Use
featNew feature
fixBug fix
docsDocumentation changes
refactorCode restructuring (no behavior change)
testAdding or fixing tests
choreMaintenance (dependencies, configs)

Examples

Good commits:

Bash
feat: add password strength indicator
fix: prevent crash when email is empty
docs: add API authentication examples
refactor: extract validation into separate function

Bad commits:

Bash
stuff
fixed
wip
asdf

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. 1

    Create a GitHub Repository

    1. Go to github.com
    2. Click +New repository
    3. Name it my-project
    4. Don't check "Initialize with README" (you already have one)
    5. Click Create repository
  2. 2

    Connect Your Local Repo

    GitHub shows you the commands. Run them:

    Bash
    git remote add origin git@github.com:yourusername/my-project.git
    git branch -M main
    git push -u origin main
  3. 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.

Branching Model
Main stays stable while you experiment

Create and Use Branches

Bash
# Create a new branch and switch to it
git checkout -b feature/new-thing
# Make changes, commit as usual
git add .
git commit -m "feat: add new thing"
# Push the branch to GitHub
git push -u origin feature/new-thing

Merge Back to Main

Bash
# Switch to main
git checkout main
# Merge your branch
git merge feature/new-thing
# Delete the branch (optional, but tidy)
git branch -d feature/new-thing
# Push the updated main
git push

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.

Pull Request Flow
Get feedback before merging

Creating a PR

  1. Push your branch to GitHub
  2. Go to your repo on GitHub
  3. Click Compare & pull request (GitHub often prompts you)
  4. Fill in the template:
Markdown
## What
Brief description of changes
## Why
Why are these changes needed?
## Changes
- Added X
- Fixed Y
- Updated Z
## Testing
How did you test this?
  1. Click Create pull request

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

Bash
git status # What's changed?
git add . # Stage all changes
git commit -m "msg" # Commit with message
git push # Upload to GitHub
git pull # Download from GitHub

Viewing History

Bash
git log --oneline # Compact history
git diff # See unstaged changes
git diff --staged # See staged changes
git show abc123 # View specific commit

Branches

Bash
git branch # List branches
git checkout -b name # Create & switch to branch
git checkout main # Switch to main
git merge name # Merge branch into current
git branch -d name # Delete branch

Undoing Things

Bash
git restore file.txt # Discard changes to file
git restore --staged file # Unstage file
git reset HEAD~1 # Undo last commit, keep changes
git reset --hard HEAD~1 # Undo last commit, delete changes

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:

Bash
# Dependencies
node_modules/
venv/
__pycache__/
# Secrets
.env
.env.local
*.key
# OS files
.DS_Store
Thumbs.db
# Build outputs
dist/
build/
*.log

Part 12: Using Claude for Git

Claude can handle the tedious parts of Git for you.

Write Commit Messages

Bash
I made these changes to auth.ts and api.ts.
Analyze my git diff and write a commit message.

Resolve Conflicts

Bash
I have a merge conflict in this file:
[paste the conflicted file]
Help me resolve it.

Write PR Descriptions

Bash
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

Bash
Git gave me this error:
[paste error]
What does it mean and how do I fix it?

Best Practices Summary


Next Steps

You know Git! Apply it to:


Resources