- Developers who already know basic commit and branch actions
- Readers who want to understand command boundaries and risk
Command Reference
git init Tutorial
Explains how git init creates a repository, how the initial branch is defined, and how it is used for both new and existing directories.
- A basic mental model of worktree, index, and commits
- Comfort reading `git status` and a small commit graph
- Using local cleanup commands on already shared history
- Continuing to rewrite before confirming a recovery path
Citations & Further Reading
- Git init [Official]
- Git Basics Getting a Git Repository [Book]
What you will learn
- Understand the core purpose of git init Tutorial
- Master the basic usage and common options of git init Tutorial
- Explains how git init creates a repository, how the initial branch is defined, and how it is used for both new and existing directories.
- Understand key concepts: Common use cases
- Know when to use this feature and when to avoid it
Start with a problem
You're working in a Git repository and need to perform a specific task — but you're not sure which command or option is the right fit, or what this command can and cannot do.
The short version
git init creates a new Git repository structure in the current directory so version control can begin there.
Common use cases
- starting a new project under Git
- bringing an existing directory under version control
- creating a local experiment repository quickly
Basic usage
git init
git init -b main
Important note
git init does not create the first commit. It only creates the repository metadata. The real history starts with your first commit.
What problem this command solves in a workflow
git init is about repository initialization, configuration, and how Git should behave by default. It may not appear every hour, but it influences whether the rest of your workflow stays stable and predictable.
Typical use cases
- Use
git initwhen bootstrapping a new repository, setting up a machine, or establishing shared team defaults. - Put
git initinto onboarding and environment validation flows so "works differently on my machine" issues get caught earlier. - When debugging behavior differences, use
git initin a clean directory to quickly create a control repository that eliminates old configuration interference.
Diagram view
Special cases and boundaries
- Configuration and initialization commands may not cause immediate incidents, but once defaults are wrong, many later commands will continuously deviate from expectations.
- If you are using
git initin a team environment, it is best to write key default configurations into documentation or scripts, rather than relying solely on personal memory. - When behavior disagrees with documentation, first inspect config scope, aliases, and local environment differences.
Try it yourself
- Practice the git-init command in a test repository and observe state changes before and after
- Experiment with different options and compare the output differences
- Simulate a real scenario where you would need to use this, and walk through the full process
Further reading
Keep going on the same topic: