basics
git init
Creates a new empty Git repository by initializing the .git metadata directory in the current or specified folder. Turns any directory into a version-controlled project.
git init [<directory>] Common flags
| Flag | Purpose |
|---|---|
| -b <name> | Set the initial branch name (e.g., main) |
| --bare | Create a bare repo with no working tree, typical for servers |
| --initial-branch=<name> | Explicit form of -b for the default branch |
| --template=<dir> | Use a custom template directory for hooks and config |
Examples
git init Initialize repo in the current directory
git init -b main my-project Create my-project/ with 'main' as the initial branch
git init --bare repo.git Create a bare server-side repository
Gotcha
Running `git init` inside an existing repo is safe for history but will re-copy templated hooks and can overwrite customized hooks in .git/hooks. If you customized hooks, back them up first.
Related commands
git clone
Downloads a repository from a remote URL into a new local directory, setting up the remote 'origin' automatically. Includes all commits, branches, and tags by default.
git config
Reads and writes Git configuration variables at system, global, or repository scope. Controls identity, aliases, editor, merge tools, and much more.
git remote
Manages the set of named remote repositories your local repo tracks, such as origin or upstream. Lets you add, rename, remove, or inspect remote URLs.
git add
Stages file changes into the index so they are included in the next commit. Supports whole files, directories, and interactive patch selection.
git commit
Records the staged snapshot to the repository history along with a message and author metadata. Every commit is identified by a unique SHA hash.