Git & GitHub
/Beginner
git init
Definition
The command used to create a new, empty Git repository or reinitialize an existing one.
Explain Like I'm New
You have a folder on your computer full of code. Git is currently ignoring it. By typing `git init`, you awaken Git. It creates a secret hidden folder called `.git` that acts as the 'brain' and starts tracking your files.
Real World Example
Starting a brand new web project from scratch on your local computer.
Common Use Cases
- •Starting new local projects
`git init` Options
| Flag | Description |
|---|---|
| `git init` | Initializes a standard local git repository in the current folder (creates `.git`). |
| `--bare` | Creates a bare repository without a working directory (used for centralized servers/remotes). |
| `-b [branch_name]` | Sets the initial branch name (e.g., `main` instead of `master`) upon creation. |
Terminal Output
bash / terminal
# Create a new folder for your project
$ mkdir my-awesome-app
$ cd my-awesome-app
# Tell Git to start tracking this folder
$ git init
# Output: Initialized empty Git repository in /path/to/my-awesome-app/.git/
# If you run 'ls -a' (list all files, including hidden ones),
# you will see the secret .git folder!
$ ls -a
# Output: . .. .git
Interview Questions
basic
- What does `git init` actually do under the hood?
intermediate
- If you delete the `.git` folder, what happens to your code?