Your first repository and commit

Beginner · 5 min

Turn a folder into a Git repository with git init, make two commits for tinynotes, and learn what the hidden .git folder and git status are telling you.

Before thisThe three areas of Git

Traversy Media · 49 min · from 14:49

Your first repository and commit

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Traversy MediaReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • git init turns the current folder into a repository by creating a hidden .git folder, and nothing else about your files changes.
  • A new file is untracked until you git add it, and it only enters history when you git commit.
  • A commit is a snapshot of everything that was staged, with an author, a date, a message and a pointer to its parent.
  • git status is the command to run constantly: it says which of the three areas holds each change and suggests the next command.
  • Deleting the .git folder deletes the entire history and leaves your working files, so never delete it casually.

The project you will keep growing

From here to the end of this roadmap you work on one small project, tinynotes: a Python script that appends a line to a text file and prints the lines back. You don’t need to know Python. The script is just something with a history to build. Make the folder and the first file:

$ mkdir tinynotes
$ cd tinynotes

Then save this as notes.py:

import sys

NOTES = "notes.txt"


def add(text):
    with open(NOTES, "a") as f:
        f.write(text + "\n")


def show():
    with open(NOTES) as f:
        print(f.read(), end="")


if __name__ == "__main__":
    if sys.argv[1] == "add":
        add(" ".join(sys.argv[2:]))
    elif sys.argv[1] == "show":
        show()

It runs as python3 notes.py add "buy milk" and python3 notes.py show. Everything below I ran with Git 2.54 and Python 3.9, with a fixed date on each commit so you can see real hashes. Yours will differ, and that is normal.

git init

Right now this is an ordinary folder. Git does nothing until you ask:

$ git init
Initialized empty Git repository in ~/tinynotes/.git/

That one command created a hidden folder, .git. It holds the whole repository: the history, the staging area, and the repository’s own config. Your files are untouched. ls -a shows the hidden entry, and ls .git lists what is inside: HEAD, config, objects, refs, hooks and a few others. The objects folder is where snapshots end up, and a later lesson opens it.

The folder holding .git is the project root. Run Git commands anywhere inside it and Git finds .git by looking upwards. This also means that deleting .git deletes the history, and your working files remain exactly as they were.

Read git status first

$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	notes.py

nothing added to commit but untracked files present (use "git add" to track)

Read it top to bottom. You are on a branch called main. There are no commits yet. notes.py is untracked, which is Git saying “I see this file, but I’m not watching it.” The last line is a hint at the next step. Get in the habit of running git status before and after almost everything. It never changes anything, and it tells you where each change sits.

Stage and commit

$ git add notes.py
$ git commit -m "Add notes.py with add and show"
[main (root-commit) 7740572] Add notes.py with add and show
 1 file changed, 20 insertions(+)
 create mode 100644 notes.py

Reading the output: main is the branch. root-commit means this commit has no parent, since it is the first. 7740572 is the start of the commit’s ID, a 40-character hash that Git abbreviates. The message follows. create mode 100644 is the file’s permission record, the ordinary non-executable kind.

Add a second file and commit it:

$ git add README.md
$ git commit -m "Add a README"
[main ea12739] Add a README
 1 file changed, 6 insertions(+)
 create mode 100644 README.md

No root-commit this time, because this commit has a parent. Look at the history:

$ git log
commit ea1273945228699ce0d42a3426a63f6f48e17ae2
Author: Ada Example <ada@example.com>
Date:   Tue Jan 6 10:00:00 2026 +0000

    Add a README

commit 774057259805843cb22d388c2add1dc06d5d509d
Author: Ada Example <ada@example.com>
Date:   Mon Jan 5 10:00:00 2026 +0000

    Add notes.py with add and show

Newest first. Each entry carries its author (from your config), a date, and the message. The next lesson digs into reading this properly.

What a commit is

A commit is a snapshot of every tracked file at the moment you committed, plus a bit of metadata: who, when, why, and which commit came before. The second commit stores both files as they stand, not “the README on its own”. Git only stores a file’s contents once if it hasn’t changed, which is why this stays cheap. How that works is a later lesson in this group.

Two habits to start with. Commit small, coherent changes, because each commit is a point you can return to. And commit working states where you can, because a history full of half-broken snapshots is hard to use later.

What the video covers

The embed plays the stretch of Traversy Media’s “Git & GitHub Crash Course 2025” from 14:49 to 19:56. Going by the creator’s timestamp list, that covers git init, git status, git add, git commit, making changes and git log: the same sequence as this lesson. It is five minutes of a 49-minute video published in January 2025. I couldn’t read a transcript, so I haven’t checked details such as which branch name his repository starts on. The channel is English-language, judged from the title and description. The video carries on into creating a GitHub repository, which this roadmap reaches in a later group, so stop the embed there. Colt Steele’s older fifteen-minute video is linked as a second take on the same ground.

Where this fits

You have a repository and two commits. Next you will read that history properly, with git log and git diff: reading history with log and diff. If you want a different second explanation of the same ground, the frontend roadmap has version control with Git.

Check yourself

  1. 01What exactly does git init create?

    A hidden .git directory holding the repository's history, staging area and config. Your project files are untouched.

  2. 02Why did git commit say nothing was committed when you had just created a file?

    The file was untracked. A commit records only what is in the staging area, so the file needs git add first.

  3. 03How many parents does the very first commit have?

    None. It is called the root commit, and every later commit points back to the one before it.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark