git init: Usage, Options & Common CI Errors
git init turns a directory into a Git repository by creating the .git folder.
Use git init to start version control in a fresh directory or to set up a bare repo for pushing to.
What it does
git init creates a new .git subdirectory containing all the repository metadata. Running it in an existing repo is safe and only reinitializes; it does not overwrite your work.
Common usage
Terminal
git init
git init --initial-branch=main my-project
git init --bare repo.gitOptions
| Flag | What it does |
|---|---|
| --bare | Create a bare repo (no working tree) for serving |
| --initial-branch=<name> / -b | Set the first branch name (default historically "master") |
| --template=<dir> | Use a custom template directory |
| --quiet / -q | Suppress output |
Common errors in CI
A common surprise is the default branch name: older Git defaults to "master" while hosts expect "main". Set it explicitly with git init -b main, or configure git config --global init.defaultBranch main so scripts are deterministic across runner images.
Related guides
git clone: Usage, Options & Common CI Errorsgit clone copies a remote repository into a new local directory. Reference for depth, branch, and submodule f…
git config: Usage, Options & Common CI Errorsgit config gets and sets Git configuration at system, global, and local scope. Reference for --global, --get,…
git remote: Usage, Options & Common CI Errorsgit remote manages the named connections to remote repositories. Reference for add, set-url, -v, remove, and…
git branch: Usage, Options & Common CI Errorsgit branch lists, creates, renames, and deletes branches. Reference for -d, -D, -m, --set-upstream-to, and th…