GitLearn — Git Data Flow
GitLearn
15px

⟳ Git Data Flow

Git has four distinct zones where your code lives. Every command moves data between exactly two of them — once you see the map, every command clicks into place.

▶ Interactive Flow

Click any command to see the exact path your data travels.

YOUR MACHINE SERVER Working Dir your edited files before staging Staging Area queued for next commit Local Repo .git folder commit history Remote GitLab shared with team git add git commit git push git fetch restore --staged git pull (fetch + merge) git clone (first time only) git restore
Click a command above to see where your data travels.
The Four Zones — explained

Your code always lives in one of these four places. Git commands are instructions to snapshot and move data between them.

Working Dir
Your live files
Exactly what's in your project folder right now. Git knows which files changed, but no snapshot has been taken yet. Changes here are not tracked until you add them.
Staging Area
The photo queue
A holding area — a precise list of which file changes go into the next commit. You control what's here via git add. Nothing is permanent yet.
Local Repo
Your commit history
The hidden .git folder. A permanent database of every commit on this machine. Entirely local — nothing is shared until you push.
Remote Repo
The shared server
Your GitLab repository. The single source of truth for the team. Changes only arrive here when you push, and others see them only after they fetch or pull.

Saving Changes — the everyday flow

Three commands, always in this order. Every commit you've ever pushed followed this exact path.

Working Dir
edited file
unsaved to Git yet
git add
Staging Area
snapshot in
the queue
git commit
Local Repo
new commit
saved in .git
git push
Remote (GitLab)
now visible
to the team
💡
You choose exactly what goes into each commit. git add is how you pick. If you changed 5 files but only want 2 in this commit, just git add those 2. The other 3 stay in Working Dir until you decide.
# Typical save-and-share flow
git status                    # see what changed
git add src/login.ts          # stage one specific file
git add src/auth/             # or stage a whole folder
git commit -m "fix: login redirect after password reset"
git push origin feature/login-fix

Getting Updates — data flows inward

Three commands bring code from the remote. They stop at different zones — that's the key difference between them.

git fetch
Remote
Local Repo
your files stay untouched
git pull
Remote
Local Repo Working Dir
fetch + merge
git clone
Remote
Working Dir Staging Local Repo
first time only
CommandDownloads to Local Repo?Updates your files?Safe mid-feature?
git fetchYes — updates origin/mainNo — Working Dir untouchedAlways safe
git pullYesYes — merges into current branchSafe on clean branch
git cloneYes — creates it from scratchYes — creates Working DirFirst time only
💡
git fetch is always safe — it never touches your Working Dir or Staging Area. After a fetch, run git log origin/main --oneline -5 to see what arrived, then consciously choose to merge or rebase.
# Safe: see what the team pushed before touching your branch
git fetch origin
git log origin/main --oneline -8     # inspect incoming commits

# Then apply when ready
git rebase origin/main               # replay your commits on top (cleaner)
# or
git merge origin/main

# Shortcut on a clean main branch
git switch main && git pull

Going Backwards — data flows leftward

Undo commands move data in the opposite direction. Knowing which zone you're targeting tells you exactly how destructive a command is.

restore --staged
Staging
Working Dir
edits preserved
git restore
Local Repo
Working Dir
⚠ overwrites edits
reset --soft
Local Repo
Staging
commit unpacked
reset (mixed)
Local Repo
Working Dir
commit unstaged
reset --hard
Local Repo
discarded
⚠ permanent loss
CommandMoves fromMoves toDanger level
git restore --staged <file>Staging AreaWorking Dir (unstages, keeps edits)Safe — edits preserved
git restore <file>Last commit (Local Repo)Working Dir (overwrites file)Destructive — edits gone
git reset --soft HEAD~1Local Repo (last commit)Staging Area (commits unpacked)Safe — changes queued
git reset HEAD~1 (mixed)Local Repo (last commit)Working Dir (commits unstaged)Safe — changes kept
git reset --hard HEAD~1Local Repo (last commit)Discarded — both zones overwrittenDestructive — gone permanently
⚠️
Once you push, don't rewrite history. git reset is fine before pushing. After pushing, use git revert instead — it adds a new commit that undoes the change, leaving history intact for teammates.
# Unstage a file (keep your edits, just remove from next commit)
git restore --staged src/config.ts

# Discard working-dir edits entirely (file goes back to last commit)
git restore src/config.ts

# Undo last commit — keep changes in Staging (ready to re-commit)
git reset --soft HEAD~1

# Undo last commit — keep changes in Working Dir (not staged)
git reset HEAD~1

# Nuclear: undo last commit and wipe all changes
git reset --hard HEAD~1

# Safe alternative after pushing: create an undo commit
git revert HEAD

Stash — the temporary shelf

Stash is a side-pocket inside your Local Repo. It temporarily holds work-in-progress so you can switch branches without committing half-done changes.

git stash
Working Dir Staging
Stash shelf
both zones cleared
git stash pop
Stash shelf
Working Dir
top entry removed
git stash apply
Stash shelf
Working Dir
entry kept in stash
# Save everything and get a clean Working Dir
git stash push -m "login form WIP"

# Switch branch, fix bug, come back
git switch main
# ... fix + commit + push ...
git switch feature/login-form

# Restore stashed work
git stash pop                        # apply top entry and remove it
git stash apply stash@{1}           # apply specific entry (keeps it in stash)
git stash list                       # see all saved entries

Quick Reference — every command in one table

Every command listed by which zones it touches and whether it's safe to run mid-feature.

CommandFrom zoneTo zoneSafe mid-feature?
git add <file>Working DirStaging AreaAlways safe
git commitStaging AreaLocal RepoAlways safe
git pushLocal RepoRemoteSafe if branch is yours
git fetchRemoteLocal Repo onlyAlways safe
git pullRemoteLocal Repo + Working DirSafe on clean branch
git cloneRemoteCreates all local zonesFirst time only
git restore --stagedStaging AreaWorking Dir (unstage)Safe — edits kept
git restore <file>Local RepoWorking Dir (overwrite)Destructive
git reset --softLocal RepoStaging AreaSafe (before push)
git reset (mixed)Local RepoWorking DirSafe (before push)
git reset --hardLocal RepoDiscards both zonesDestructive
git revertLocal RepoNew commit addedAlways safe
git stashWorking Dir + StagingStash shelfAlways safe
git stash popStash shelfWorking DirAlways safe