git init — Starting a Repository
Asha's recipe-box folder has three files and no history. One command turns it into a Git repository, and from that moment Git can start recording snapshots. It is also the command people most often run in the wrong folder.
The rule
git initadds a hidden.gitfolder; that folder is the repository.
Run it inside the project folder:
cd recipe-box
git initGit replies with something like Initialized empty Git repository in /Users/asha/recipe-box/.git/. Your files are untouched. The new, hidden .git folder holds everything Git knows: every snapshot, every branch, and the repository's own settings.
That gives two parts to every project:
- The working directory: the ordinary files you edit (
README.md,pancakes.md,chai.md). - The repository: the
.gitfolder with the history.
Straight after git init, the history is empty. The files are untracked: Git sees them but has not been told to record them yet.
git status
# On branch main
# No commits yet
# Untracked files:
# README.md
# chai.md
# pancakes.mdNothing is recorded until you ask. git init only prepares the storage; the next lessons show how files move from untracked to committed, one deliberate step at a time.
Some useful facts:
- Want a new folder and a repository in one go?
git init recipe-boxcreates the folder too. - Running
git initagain in the same folder is harmless; it does not wipe history. - Deleting the
.gitfolder deletes the entire history. The files remain, but the project is no longer a repository. - On older Git versions the first branch may be called
master. Setinit.defaultBranchtomain, as in the last lesson, or rungit init -b main.
The shortcut
Before running git init, ask "Is this the top folder of one project?" The folder where you run it becomes the root of everything tracked beneath it.
Check where you are
pwdprints/Users/asha/recipe-box. This is the project's top folder.
If you ever see thousands of untracked files you did not expect, you are probably inside a repository you created by accident. Find it with git rev-parse --show-toplevel, then remove that stray .git folder with care.
Drills
Answer fast — trust the rule.
What does git init create?
Right after git init, how does git status describe Asha's existing recipe files?
What happens if you delete the .git folder of a project?
Which command makes a new folder called recipe-box and initialises it as a repository?
Remember
git initadds a hidden.gitfolder; that folder is the repository.- Run it only at the top folder of one project.
- Deleting
.gitdeletes history, not files; runninggit inittwice is harmless.
