Git, GitHub & DevOps/01intro11 min

Git — data model and basic commands

Git is not "saving diffs"

Contrary to intuition, Git does not keep a list of changes. Every commit is a snapshot of the entire file tree at a given moment, plus a pointer to its parent. Understanding this model makes the rest of the commands stop being magic.

Four concepts that explain everything

ObjectWhat it is
BlobThe contents of a single file
TreeA directory — a list of blobs and subtrees
CommitA snapshot of a tree + author + pointer to the parent
Ref / branchA movable pointer to a specific commit

A branch (main, feature/...) is just a label pointing to a commit. That is why creating a branch is instant — it writes a single SHA, not a copy of the files. HEAD is the pointer to "where you are right now".

Three states of a file

Every change travels through three areas:

working directory  ->  staging area (index)  ->  repository
     (you edit)          (git add)               (git commit)
  • Working directory — your files on disk.
  • Staging area — what will go into the next commit (git add).
  • Repository — the persisted history (git commit).

Tip: The staging area is not bureaucracy, it is a tool. It lets you put only part of a file's changes into a commit and build a clean, logical commit instead of a "throw everything in at once" bag.

Everyday commands

# Repo state - what's changed, what's staged
git status

# Stage a specific file or everything
git add src/app/page.tsx
git add .

# Commit the snapshot
git commit -m "feat: dodaj listę raportów"

# Commit history (concise)
git log --oneline --graph --decorate

# Differences
git diff            # working vs staging
git diff --staged   # staging vs last commit

Working with branches and the remote repo

# Create and switch to a new branch
git switch -c feature/lista-raportow

# Pull changes from GitHub
git pull

# Push the branch to the remote repo
git push -u origin feature/lista-raportow

Undoing — safely

# Discard changes in the working directory (restore from the last commit)
git restore src/app/page.tsx

# Unstage a file (keep the changes)
git restore --staged src/app/page.tsx

# Amend the last commit (e.g. a typo in the message)
git commit --amend

Tip: --amend rewrites history — only use it on commits you have not pushed yet. After a push, fix things with a new commit.

Why all of this is fast

Because Git works locally on pointers and snapshots. Most commands (log, branch, diff, commit) never touch the network. The network is only needed for push/pull/fetch.

Summary

Git = a chain of snapshots linked by pointers; a branch is a movable label. Day to day you only need: status, add, commit, log, switch, pull, push. This model is the foundation for branching and Pull Requests in the next lesson.