🏗️
🏗️

The 4 Domains

  • Master the 4-layer structure: Workspace, Index, Local Repo, and Remote Repo.

  • Knowing where your files 'live' is the key to Git mastery.

  • Precision control of data movement across domains via modern commands.

Slide 1 of 3Remaining 2

1. Git Architecture: The Four Domains

The first step in understanding Git is knowing where your changes are and where they need to go. Git is divided into four distinct areas:

graph LR WS[Workspace] -- "git add" */} IDX[Staging Area] IDX -- "git commit" */} LOC[Local Repo] LOC -- "git push" */} REM[Remote Repo] REM -- "git fetch" */} LOC LOC -- "git switch" */} WS IDX -- "git restore" */} WS style WS fill:#f9f,stroke:#333 style IDX fill:#bbf,stroke:#333 style LOC fill:#bfb,stroke:#333 style REM fill:#fbb,stroke:#333
  • Workspace : Where you are actually editing your files.
  • Index (Staging Area) : Where you save changes temporarily to be included in the next commit.
  • Local Repo : Your local database of commit history on your PC.
  • Remote Repo : The shared database on a server like GitHub.

2. Git is a Graph (DAG)

Git history is not just a line; it’s a DAG (Directed Acyclic Graph) .

gitGraph commit id: "Initial" commit id: "Add logic" branch develop checkout develop commit id: "Feature A" commit id: "Feature B" checkout main merge develop commit id: "Release 1.0"

Each commit has a pointer to its “parent,” and branches (like main or develop) are just pointers (movable labels) pointing to specific commits.


3. Modern Git: From ‘checkout’ to ‘switch’ and ‘restore’

By 2026, git checkout has become a legacy command in modern dev environments. This is because checkout was too complex, handling both “branch switching” and “file restoration,” leading to high risks of accidental data loss.

Since Git v2.23, these roles have been explicitly split:

Role Legacy Command (Deprecating) Modern Command (Recommended)
Switch Branch git checkout <branch> git switch <branch>
Create New Branch git checkout -b <new> git switch -c <new>
Discard File Changes git checkout -- <file> git restore <file>
Unstage Files git reset HEAD <file> git restore --staged <file>

Why the upgrade?

  • + Clear separation of intent (Switching vs. Restoring) reduces human error
  • + Argument interpretation is more intuitive, preventing unintentional overwrites
  • + This is the standard for 2.23+; most AI assistants and docs now prioritize these.
  • - Need to retrain years of muscle memory (typing habits)
  • - Might not work on extremely old server environments with outdated Git versions

4. Daily Workflow: The 2026 Standard

Check the standard development cycle with this roadmap:

1

1. Sync

git pull origin main --rebase

First thing in the morning
2

2. Start Feature

git switch -c create-feature

+5 min
3

3. Staging

git add .

+30 min
4

4. Commit

git commit -m "feat: add new visualization"

+2 min
5

5. Push/PR

git push origin create-feature

On completion
ℹ️

Tip : Using git pull --rebase keeps your history clean and linear, avoiding unnecessary merge commits.


5. Advanced Basics: Sparse Checkout

When working in massive monorepos, cloning everything is inefficient. In 2026, git sparse-checkout is the standard way to handle large repositories.

$ git commit -m \"Add user authentication feature\"

This allows you to work even in multi-gigabyte repositories using only a few megabytes of disk space.


6. Summary: Thinking in Graphs

If you get lost in Git, always ask: “Where am I in the graph (commit), and where are my branch pointers pointing?”

引用: YouTube

May your Git life be smooth and logical in 2026.