Files
mintlify__docs/git/init.mdx
2026-02-09 20:46:44 +00:00

80 lines
1.6 KiB
Plaintext

---
title: git init
description: Initialize a new Git repository
---
Initialize a new Git repository in the current directory.
## Syntax
```bash
git init [options] [directory]
```
## Description
`git init` creates a new Git repository by creating a `.git` subdirectory with all necessary repository files. This transforms an ordinary directory into a Git repository that can track changes.
## Common usage
Initialize a repository in the current directory:
```bash
git init
```
Initialize a repository in a specific directory:
```bash
git init my-project
```
## Options
<ParamField path="--bare" type="flag">
Create a bare repository without a working directory, typically used for remote repositories
</ParamField>
<ParamField path="--initial-branch" type="string">
Set the name of the initial branch (default is usually `main` or `master`)
```bash
git init --initial-branch=main
```
</ParamField>
<ParamField path="--template" type="path">
Specify a directory to use as template for the repository
</ParamField>
## Examples
### Create a new project
```bash
mkdir my-project
cd my-project
git init
```
### Initialize with a specific branch name
```bash
git init --initial-branch=main
```
## What happens after init?
After running `git init`, you typically:
1. Add files to track: `git add .`
2. Create your first commit: `git commit -m "Initial commit"`
3. Connect to a remote: `git remote add origin <url>`
4. Push to remote: `git push -u origin main`
## Related commands
- [git clone](/git/clone) - Copy an existing repository
- [git add](/git/add) - Start tracking files
- [git commit](/git/commit) - Save your changes