git init
Turn any folder into a Git repository.
git initWhat it does
git init creates a hidden .git directory inside your project. That directory is the entire repository — every object, every pointer, every piece of history lives inside it. From this moment, Git can track what happens to every file in the project.
git init materializes the .git folder
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Choose an empty room
Point git at any folder — even one with nothing in it yet.
git initA bare folder, before git arrives
Under the hood
Git creates the .git folder
git init writes a .git directory containing the four core structures: objects/ (empty), refs/ (empty), HEAD (a file pointing at refs/heads/main), and index (an empty binary staging file).
mkdir .git
mkdir .git/objects/{info,pack}
mkdir .git/refs/{heads,tags}
echo 'ref: refs/heads/main' > .git/HEADHEAD is born
HEAD is just a text file holding the name of the current branch. It points at refs/heads/main, but that branch file doesn't exist yet — it appears with your very first commit.
cat .git/HEAD # → ref: refs/heads/main
Nothing is tracked yet
No objects exist. No files are in the index. Git simply says 'demonstrated' and waits. The working directory itself is untouched — Git is a layer on top, not a copy.
Aliases the pros type
Memorize the git init concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git initg initgit initCommon global alias where g = git.
gigit initBare initials some shells define.
g init -ygit init -b mainSome setups alias this to skip the default-branch warning.
Command anatomy
<directory>Initialize a repo in a specific folder instead of the current one.
-b <name>Set the initial branch name (defaults to main).
--bareCreate a bare repo — no working directory, refs only. Used on servers.
When to reach for it
Starting a brand-new project and you want version control from day one.
You downloaded someone's code without a .git folder and want your own history.
You're exploring Git internals and want a clean sandbox: git init /tmp/lab.
Pro tip
Newer Git versions default the branch to main. To check: `git init -h` shows the default branch name as the --initial-branch hint.