Command Palette

Search for a command to run...

Hectal
PHASE 0Beginner ~14 min· topic 3 of 5

Topic 0.3

Your First Repo: init, status, and Your First Commit

In one line

git init creates a brand-new repository from any folder, and add + commit is the two-step ritual that turns a pile of files into permanent, recorded history — everything else in Git builds on this loop.

0/5 · 0%

Key ideas

  1. 01

    git init turns the CURRENT directory into a Git repository by creating a hidden .git folder — this single folder IS the entire repository: all of its history, branches, and configuration live inside it. Deleting .git (carefully, deliberately) instantly and completely un-Gits a folder, leaving your actual files untouched.

  2. 02

    A brand-new repository starts with ZERO commits and nothing tracked — every file in the folder is 'untracked' until you explicitly git add it, meaning Git never accidentally starts tracking something you didn't ask it to.

  3. 03

    The core loop, repeated constantly for the rest of your Git-using life: edit files → git add <files> (stage the ones you want in this commit) → git commit -m "message" (seal them into history) → repeat. Every single workflow this course covers, no matter how advanced, is built on top of this exact loop.

  4. 04

    A commit MESSAGE (-m "...") is not optional decoration — it's the primary way anyone (including future you) understands WHY a change was made, months or years later, without having to reverse-engineer it from the code alone. Phase 7 covers writing genuinely good commit messages in depth.

  5. 05

    git log shows the commit history you've built — each commit has a unique ID (a SHA, covered next topic), an author, a date, and the message you wrote. Running git log after every few commits, just to see the history taking shape, is a good habit to build from day one.

  6. 06

    git clone <url> is the equivalent of git init for a repository that ALREADY exists somewhere else (GitHub, a teammate's machine) — it downloads the entire history and sets up a working directory in one command, ready to use immediately, rather than starting empty.

Code & diagrams

first-repo.shmarkdown

The complete loop, start to finish, on a throwaway folder.

# Create a brand-new repository
mkdir ~/scratch/my-first-repo && cd ~/scratch/my-first-repo
git init
# Initialized empty Git repository in .../my-first-repo/.git/

# Nothing tracked yet
git status
# "No commits yet" ... "nothing to commit"

# Create a file and check its status
echo "# My First Repo" > README.md
git status
# README.md shows as untracked

# Stage it
git add README.md
git status
# README.md shows as "Changes to be committed"

# Commit it — your first permanent snapshot
git commit -m "Initial commit"

# See your history
git log
# shows one commit, with its SHA, author, date, and message

# Make a second commit to see history grow
echo "A short description of the project." >> README.md
git add README.md
git commit -m "Add project description"
git log --oneline
# now shows two commits, most recent first

Explain it without notes

01

What exactly happens on disk when you run git init, and what happens if you delete the .git folder afterward?

02

Why does a commit message matter as much as the code change itself, according to this topic?

Practice

01

Create a brand-new folder, initialize it as a Git repo, and make three separate commits, checking git log after each one to watch the history grow.

02

Delete the .git folder from a test repo (never a real project) and confirm with ls -la that your actual files are all still there, completely untouched, even though git status now fails with 'not a git repository.'

Trade-offs

  • ↔

    Committing very frequently, in small deliberate steps, creates a genuinely useful, fine-grained history that's easy to review and revert piece by piece — but it does mean more discipline writing a real message each time, versus one giant commit at the end of a day's work, which is faster in the moment but produces a nearly useless history for anyone (including future you) trying to understand what happened and why.

Done when you can

  • I can create a new Git repository from scratch with git init.

  • I can complete the add → commit loop and explain each step.

  • I understand that .git is the entire repository, separate from my actual files.