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.