Skip to the workspace
Pebellslearn by building
Learn the Basics  ›  Capstone Project

git init — Starting a Repository

git init 12 mingit init turns a folder into a repository by adding a hidden .git folder that stores all history, leaving the existing files untracked.

git github / git init — Starting a Repository

Explore each scene at your own pace.

01 · The rule

The rule

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 init adds a hidden .git folder; that folder is the repository.

Run it inside the project folder:

cd recipe-box
git init

Git 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 .git folder 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.md

Nothing 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-box creates the folder too.
  • Running git init again in the same folder is harmless; it does not wipe history.
  • Deleting the .git folder 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. Set init.defaultBranch to main, as in the last lesson, or run git init -b main.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.