Appearance
Your First Commit
You have a directory full of code (or just a single file) and you want Git to track it. This guide walks through the exact sequence from nothing to your first saved snapshot.
Scenario
You just created a project. It has two files:
my-project/
index.html
style.cssYou want Git to watch these files so you can save checkpoints, experiment without fear, and look back at what changed.
Step by step
1. Create the repository
bash
cd my-project
git initOutput:
Initialized empty Git repository in /home/you/my-project/.git/git init creates a hidden .git directory. That directory is the repository — it holds every commit, every version, every config setting. Your working files stay right where they are.
2. Check what Git sees
bash
git statusOutput:
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html
style.css
nothing added to commit but untracked files present (use "git add" to track)"Untracked" means Git sees the files but is not watching them yet. They are not part of any snapshot. git status is your dashboard. Run it whenever you're unsure what state things are in.
3. Stage the files
bash
git add index.html style.cssNothing prints on success. Run git status again:
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
new file: style.cssThe files moved to "staged" status. Staging is Git's intermediate area — you pick which changes go into the next commit. You can stage some files, make more edits, stage those too, then commit everything at once.
Stage every untracked file at once:
bash
git add .The dot means "the current directory and everything in it." Use it when you want to add all new and modified files.
4. Commit
bash
git commit -m "Initial commit: project scaffold"Output:
[master (root-commit) a1b2c3d] Initial commit: project scaffold
2 files changed, 42 insertions(+)
create mode 100644 index.html
create mode 100644 style.cssThat's it. Your first snapshot is saved. The string a1b2c3d is the abbreviated commit SHA — a unique identifier for this commit. Every commit gets one.
5. View what you just did
bash
git logOutput:
commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 (HEAD -> master)
Author: Your Name <you@example.com>
Date: Mon Nov 10 12:00:00 2026 -0500
Initial commit: project scaffoldgit log shows the commit history. Right now there's one entry — the one you just made. HEAD -> master means you are on the master branch at this commit.
What's happening here
| Step | What Git stores | Where it lives |
|---|---|---|
git init | Creates the .git database | .git/ directory |
git add | Writes a blob of each file's content + a staging entry | .git/objects/ + .git/index |
git commit | Writes a tree object (directory listing) + a commit object pointing to it | .git/objects/ |
A commit is not a diff. It is a full snapshot of every staged file, stored as a tree of content-addressable objects. Git only shows diffs when you ask for them.
Common mistakes
| Mistake | What happens | How to fix |
|---|---|---|
Forgetting git add | git commit says "nothing to commit" | Run git add first, then commit |
Committing without -m | Git opens a text editor (usually vim) | Type your message, save, and quit. Or git commit --amend -m "new message" to fix later |
git add of the wrong file | File is staged when you didn't want it | git rm --cached <file> unstages without deleting the working copy |
git init in the wrong directory | Git tracks the wrong folder | Delete .git/ (rm -rf .git) and re-init in the right place |
| No email configured | Git error: "please tell me who you are" | Set git config --global user.email "you@example.com" |
Quick reference
bash
git init # Create a new repo in the current directory
git status # Show working tree and staging state
git add <file> # Stage a file for the next commit
git add . # Stage everything
git commit -m "message" # Commit staged changes with a message
git log # Show commit historyNext steps
Now that you have one commit, try editing a file and repeating steps 2-4. The second commit will show what changed since the first one. That's the core loop of Git: edit, stage, commit, repeat.