0
0
Gitdevops~5 mins

Git mental model (snapshots not diffs) - Commands & Configuration

Choose your learning style9 modes available
Introduction
Git saves your project by taking snapshots of all files at each save point, not by saving only the changes. This helps you see the whole project state at any time easily.
When you want to save your work safely and be able to go back to any previous version.
When you want to share your project with others and track all changes clearly.
When you want to understand how your project looked at a specific moment in time.
When you want to avoid losing work by saving snapshots often.
When you want to compare different versions of your project easily.
Commands
This command creates a new Git repository in your current folder so Git can start tracking snapshots of your project.
Terminal
git init
Expected OutputExpected
Initialized empty Git repository in /your/path/.git/
This command tells Git to prepare all current files for the next snapshot. It stages the files so they will be included in the next commit.
Terminal
git add .
Expected OutputExpected
No output (command runs silently)
This command takes a snapshot of all staged files and saves it with a message describing the snapshot.
Terminal
git commit -m "Initial snapshot"
Expected OutputExpected
[master (root-commit) abcdef1] Initial snapshot 3 files changed, 30 insertions(+) create mode 100644 file1.txt create mode 100644 file2.txt create mode 100644 file3.txt
-m - Adds a message describing the snapshot
This command shows a list of all snapshots taken so far, with their short IDs and messages.
Terminal
git log --oneline
Expected OutputExpected
abcdef1 Initial snapshot
Key Concept

If you remember nothing else from this pattern, remember: Git saves your project by taking full snapshots of all files at each commit, not just the changes.

Common Mistakes
Trying to commit without adding files first
Git only saves files that have been staged with 'git add', so the commit will be empty if you skip this step.
Always run 'git add' on the files you want to include before committing.
Thinking Git saves only file differences
Git actually saves snapshots of the entire project state, which helps it restore any version quickly and reliably.
Understand that each commit is a snapshot of all files, so you can see the whole project at that point.
Summary
Initialize a Git repository with 'git init' to start tracking snapshots.
Use 'git add' to stage files you want to include in the next snapshot.
Run 'git commit -m "message"' to save a snapshot with a description.
Use 'git log --oneline' to see all saved snapshots and their messages.