git init
git
Usage
git init [-b <branch>] [<directory>]Turns a folder into a new git repository; init alone tracks nothing, so add and commit still have to happen.
Common flags
| Flag | Meaning |
|---|---|
| -b <name> | name the first branch, e.g. main |
| --bare | repository with no working tree, for a server |
| --template=<dir> | copy hooks and files from a template directory |
| --separate-git-dir=<dir> | keep the .git directory somewhere else |
| -q | print nothing but errors |
Examples
git initturns the current folder into a repository by creating .git
git init -b main my-appcreates my-app/ with its first branch named main
git init --separate-git-dir=~/gitdirs/app.gitkeeps the .git directory elsewhere and leaves a pointer file
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git init do?
Turns a folder into a new git repository; init alone tracks nothing, so add and commit still have to happen.
Q. How do I type it?
git init [-b <branch>] [<directory>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-init