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.
Creating a practice repository
Section titled “Creating a practice repository”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:
mkdir git-practicecd git-practiceNow initialize it as a Git repository:
git initYou will see:
Initialized empty Git repository in /path/to/git-practice/.git/That is it. The folder is now a Git repository.
What git init creates
Section titled “What git init creates”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.
Running git status
Section titled “Running git status”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:
git statusOutput:
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
mainbecause 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.
Creating a file to track
Section titled “Creating a file to track”Create a simple text file so Git has something to see:
echo "# Git Practice" > notes.txtRun 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.
Exercise
Section titled “Exercise”- Open your terminal and create the practice folder:
mkdir git-practicecd git-practicegit init- Confirm that
.gitwas created. On macOS/Linux:
ls -laYou should see the .git directory in the output.
-
Run
git statusand read the output. Note the branch name and the “No commits yet” message. -
Create a file called
notes.txtwith any content, then rungit statusagain and observe how the output changes.
git initturns any folder into a Git repository by creating a hidden.gitdirectory inside it.- The
.gitdirectory stores all history and configuration. You never edit it directly. git statusshows 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 initworks 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.