learn git.
0/25 done
learn git/the basics/course 03 of 25

git init: turn a folder into a repository

One command. From now on, git is watching this folder.

5 min read·3 sections·2 tasks
the key idea

git init creates the hidden .git folder — the moment a normal folder gains a memory.

01What init actually does

A repository is simply a folder that git is tracking. The word sounds official; it means nothing more than that. You turn a normal folder into a repository with one command, run once, at the top of the project: git init.

What physically happens: git creates a hidden folder named .git inside your folder. That is the entire effect. Your files do not move, nothing is renamed, the folder looks exactly the same in your file manager — but from this moment, the machinery for saving photographs exists.

[bash]· the whole command
git init
Repository = tracked folder

Repository is not a special kind of project. It is your ordinary project folder plus a hidden .git inside it. Delete the .git folder and it is an ordinary folder again.

02Reading git's reply

Git answers Initialized empty Git repository in .../your-folder/.git/. Translated into human: done, the machinery is in place, and the album is currently empty — you have not taken any photographs yet. The word empty in the reply refers to the history, not your files; your files are all still there, just not saved into git yet.

Running git init a second time is harmless — git answers Reinitialized and continues. But in real life you only run it once per project. Running it inside a folder that is already inside another repository causes confusion, so keep one repository per project, at the top.

03Checking that it worked

The habit to build right now: after anything important, ask git for a status report. git status is that report — it tells you which branch you are on, what is saved, and what is waiting. On a brand-new repository it says No commits yet, which is exactly true: the camera exists, but you have not clicked it.

[bash]· your new favourite command
git status
Why the branch is called main

On first commit, git needs a name for your first line of history. It used to be master; the world moved to main in 2020. Old tutorials saying master are simply old — the two names mean the same thing.

>>

Practice

The practice terminal below is a normal folder. Turn it into a git repository.

[practice]· a real terminal, safely simulated
practice terminal — everything here is simulated, nothing can break
type 'help' to see the commands this terminal understands
~/my-project $
Your tasks0/2 done
  1. 01.Run git init.

    hint: Type: git init

  2. 02.Ask git for a status report.

    hint: Type: git status