Skip to content

Initializing Your First Repository

A Git repository is just a regular folder with one addition: a hidden .git directory inside it that stores the entire version history. You turn any folder into a Git repository by running a single command.

For this module you will use a dedicated practice folder separate from your STO project. This keeps your experiments isolated and lets you run commands freely.

Create the folder and navigate into it:

Terminal window
mkdir git-practice
cd git-practice

Now initialize it as a Git repository:

Terminal window
git init

You will see:

Initialized empty Git repository in /path/to/git-practice/.git/

That is it. The folder is now a Git repository.

git init creates a hidden .git directory inside your folder. This directory contains everything Git needs to track the project:

git-practice/
.git/
HEAD
config
objects/
refs/

You will never need to edit anything inside .git directly. Git manages it automatically. But knowing it is there answers an important question: if you ever want to stop tracking a folder with Git, deleting the .git directory removes all tracking and history completely. The rest of your files stay untouched.

git status is one of the most important Git commands. It tells you the current state of your repository — what files exist, what has changed, and what is staged for the next commit.

On a brand-new, empty repository:

Terminal window
git status

Output:

On branch main
No commits yet
nothing to commit (create/copy files and begin tracking)

Three things to note:

  • On branch main — you are on the default branch, named main because of the configuration you set in the previous lesson.
  • No commits yet — the repository has no history.
  • nothing to commit — there are no files for Git to track yet.

Create a simple text file so Git has something to see:

Terminal window
echo "# Git Practice" > notes.txt

Run git status again:

On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
notes.txt
nothing added to commit but untracked files present (use "git add" to track)

notes.txt is now listed as untracked. Git can see the file exists, but it has not been told to track it yet. That is the next step — staging and committing — which the following two lessons cover.

Initializing a repository in an existing folder

Section titled “Initializing a repository in an existing folder”

git init works on existing folders too, not just new empty ones. If you run it inside your STO project folder, Git will immediately see all of your existing files as untracked and ready to be added to a first commit.

You do not need to do this now — Module 07 walks through that process with your STO project. For now, continue working in git-practice.

  1. Open your terminal and create the practice folder:
Terminal window
mkdir git-practice
cd git-practice
git init
  1. Confirm that .git was created. On macOS/Linux:
Terminal window
ls -la

You should see the .git directory in the output.

  1. Run git status and read the output. Note the branch name and the “No commits yet” message.

  2. Create a file called notes.txt with any content, then run git status again and observe how the output changes.

  • git init turns any folder into a Git repository by creating a hidden .git directory inside it.
  • The .git directory stores all history and configuration. You never edit it directly.
  • git status shows the current state of your repository — the branch you are on, uncommitted changes, and untracked files.
  • A file is untracked when Git can see it exists but has not been told to include it in commits.
  • git init works on both new and existing folders.

The next lesson introduces the three-area model — the working tree, staging area, and repository — which explains exactly what happens between creating a file and saving it in Git’s history.