Progress:
TIER 1 · MODULE 01· Basics

git init

Bootstrap a .git directory in any folder and turn it into a Git repo.

🎯 What & why

Turn an ordinary directory into a Git repository. Creates a .git/ subdirectory containing the object database, the HEAD pointer, an empty index, and a default branch ref. Nothing else changes — your files are untouched.

🧠 Mental model

After git init, you have a tracker watching the directory but tracking nothing yet. The object database is empty. HEAD is a symbolic ref pointing at refs/heads/master (or main), but that ref doesn't exist on disk until you make your first commit. Knowing that explains why git log errors right after init: there's no commit to walk.

🛠️ Synopsis

git init [-q | --quiet] [--bare] [--template=<dir>]
         [--separate-git-dir=<git-dir>] [--object-format=<format>]
         [-b <branch> | --initial-branch=<branch>]
         [--shared[=<perm>]] [<directory>]

🎚️ Switches & options

FlagWhat it does
-b <name>Set the initial branch name (e.g. -b main). Beats setting init.defaultBranch in config when you only want it for this repo.
--bareMake a bare repo — no working tree. Used for serving repos over the network.
--template=<dir>Copy hooks/info from a template directory into the new .git/.
--separate-git-dir=<dir>Put the .git contents somewhere else; leave a .git file in the working tree pointing to it. Useful for SSDs/HDDs split, or for putting .git outside the workspace.
--shared=groupSet group-writable permissions on the new repo. For shared NFS/multi-user setups.
--object-format=sha256Use SHA-256 instead of SHA-1. Almost no remote ecosystem speaks it yet — set it knowing what you'll lose.
--quietSuppress the friendly status output.

💡 Use cases

🧪 Examples

Init in the current directory.
$ git init
Initialized empty Git repository in /home/me/proj/.git/
Init with main as the initial branch (no global config required).
$ git init -b main
Initialized empty Git repository in /home/me/proj/.git/
Bare repo, suitable for git clone user@host:repos/proj.git.
$ git init --bare /srv/git/proj.git
Initialized empty Git repository in /srv/git/proj.git/
Reinitialize an existing repo (refreshes hooks template, keeps history).
$ git init -b main
Reinitialized existing Git repository in /home/me/proj/.git/

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.