Fundamentals

From "final_v2" folder chaos to Git immutability

Saving manual copies with arbitrary names causes lost code, accidental overwrites, and zero traceability. Git models the project as a directed sequence of complete, cryptographically identified snapshots.

Compare traditional copy chaos with the Git Directed Acyclic Graph.
Archaic manual management (Save as...)
📁
proyecto_final/ Yesterday's version
📁
proyecto_final_FINAL/ What changed? Nobody knows
📁
proyecto_final_FINAL_v2_este_si/ Overwrote teammate's work

⚠️ Zero traceability, no authors, no hashes, impossible to diff changes.

Lifecycle

The three-state cycle: Working Tree, Staging, and History

A file does not jump directly from your editor to history. First it lives modified on disk (Working Tree), then it is surgically staged with git add (Staging Area), and finally it is sealed with git commit.

1. Working Tree Files on disk
index.html Clean

No pending changes.

2. Staging Area (Index) Snapshot staging
Staging empty (use git add)
3. Repositorio (.git) Immutable history
Commit a0f12c HEAD › main

Current history in sync.

$ Repository is clean. Click "1. Edit index.html" to start the cycle.
Internal structure

Commit anatomy: a 4-part cryptographic object

A commit does not store simple diffs. It is an immutable object pointing to a file Tree, its parent commit, author metadata, and the descriptive message.

Select Commit
Object Type: commit
SHA-1 Hash: 4b71e09c12a78f3d4b6890123456789abcdef10
Tree (Snapshot): tree 87e1a3b (src/, index.html, styles.css)
Parent: parent 1c028ea (initial commit)
Author & Committer: Facundo Uferer <dev@facundouferer.com>
Commit Message:

feat: add header navigation and semantic landmarks

Pointers and references

HEAD: the compass pointing to your current position

In Git, branches are not heavy folders: they are lightweight text pointers. HEAD is a special reference pointing to the active branch, ensuring the next commit links right where you stand.

Watch HEAD advance with each commit or branch switch.
HEAD ↓ refs/heads/main
main
C1
C2

HEAD points to main at commit C2. Every new commit will automatically advance the main pointer.

Technical inspection

State diagnosis and history reading with status and log

Accurately interpreting git status output prevents disasters. Learn to identify Untracked files, Staged changes, and branches ahead of remote.

bash — git-course (zsh)
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   src/components/Navbar.astro

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
	modified:   src/pages/index.astro

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	temp-notes.txt
Green (Staged)

Files added with git add. Will be included in the next snapshot.

Red (Not staged)

Files modified on disk but not yet indexed in Staging Area.

Untracked

Brand-new files that Git has never tracked in this project.

Professional rules

Golden checklist to keep your repository pristine

Mastering Git is about discipline, not memorizing commands. Review these 4 essential architectural rules before your next commit.

01

Set your identity before your first commit

Git bakes user.name and user.email into each SHA-1 hash immutably. Committing with wrong emails requires rewriting history later.

git config --global user.name "Tu Nombre"
git config --global user.email "tu@email.com"
02

Surgical staging: avoid blind "git add ."

Use Staging as a workbench: stage only files that belong to the exact same logical unit. Consider git add -p to inspect hunks.

git add src/components/Header.astro
git status
03

Atomic and testable commits

Each commit should compile, pass tests, and serve one purpose. If you need "and" to describe it (e.g. "add login and restyle footer"), split it in two.

04

Branch out for every non-trivial change

Never code directly on main. Isolating features in dedicated branches lets you experiment, pivot, or discard cleanly.

git switch -c feature/auth-login