6 git-init - Create an empty Git repository or reinitialize an existing one
12 git init [-q | --quiet] [--bare] [--template=<template-directory>]
13 [--separate-git-dir <git-dir>] [--object-format=<format>]
14 [--ref-format=<format>]
15 [-b <branch-name> | --initial-branch=<branch-name>]
16 [--shared[=<permissions>]] [<directory>]
22 This command creates an empty Git repository - basically a `.git`
23 directory with subdirectories for `objects`, `refs/heads`,
24 `refs/tags`, and template files. An initial branch without any
25 commits will be created (see the `--initial-branch` option below
28 If the `GIT_DIR` environment variable is set then it specifies a path
29 to use instead of `./.git` for the base of the repository.
31 If the object storage directory is specified via the
32 `GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories
33 are created underneath; otherwise, the default `$GIT_DIR/objects`
36 Running `git init` in an existing repository is safe. It will not
37 overwrite things that are already there. The primary reason for
38 rerunning `git init` is to pick up newly added templates (or to move
39 the repository to another place if `--separate-git-dir` is given).
47 Only print error and warning messages; all other output will be suppressed.
51 Create a bare repository. If `GIT_DIR` environment is not set, it is set to the
52 current working directory.
54 `--object-format=<format>`::
55 Specify the given object _<format>_ (hash algorithm) for the repository. The valid
56 values are `sha1` and (if enabled) `sha256`. `sha1` is the default.
58 include::object-format-disclaimer.txt[]
60 `--ref-format=<format>`::
61 Specify the given ref storage _<format>_ for the repository. The valid values are:
63 include::ref-storage-format.txt[]
65 `--template=<template-directory>`::
66 Specify the directory from which templates will be used. (See the "TEMPLATE
67 DIRECTORY" section below.)
69 `--separate-git-dir=<git-dir>`::
70 Instead of initializing the repository as a directory to either `$GIT_DIR` or
71 `./.git/`, create a text file there containing the path to the actual
72 repository. This file acts as a filesystem-agnostic Git symbolic link to the
75 If this is a reinitialization, the repository will be moved to the specified path.
78 `--initial-branch=<branch-name>`::
79 Use _<branch-name>_ for the initial branch in the newly created
80 repository. If not specified, fall back to the default name (currently
81 `master`, but this is subject to change in the future; the name can be
82 customized via the `init.defaultBranch` configuration variable).
84 `--shared[=(false|true|umask|group|all|world|everybody|<perm>)]`::
86 Specify that the Git repository is to be shared amongst several users. This
87 allows users belonging to the same group to push into that
88 repository. When specified, the config variable `core.sharedRepository` is
89 set so that files and directories under `$GIT_DIR` are created with the
90 requested permissions. When not specified, Git will use permissions reported
93 The option can have the following values, defaulting to `group` if no value
100 Use permissions reported by `umask`(2). The default, when `--shared` is not
106 Make the repository group-writable, (and `g+sx`, since the git group may not be
107 the primary group of all users). This is used to loosen the permissions of an
108 otherwise safe `umask`(2) value. Note that the umask still applies to the other
109 permission bits (e.g. if umask is `0022`, using `group` will not remove read
110 privileges from other (non-group) users). See `0xxx` for how to exactly specify
111 the repository permissions.
117 Same as `group`, but make the repository readable by all users.
121 _<perm>_ is a 3-digit octal number prefixed with `0` and each file
122 will have mode _<perm>_. _<perm>_ will override users' `umask`(2)
123 value (and not only loosen permissions as `group` and `all`
124 do). `0640` will create a repository which is group-readable, but
125 not group-writable or accessible to others. `0660` will create a repo
126 that is readable and writable to the current user and group, but
127 inaccessible to others (directories and executable files get their
128 `x` bit from the `r` bit for corresponding classes of users).
131 By default, the configuration flag `receive.denyNonFastForwards` is enabled
132 in shared repositories, so that you cannot force a non fast-forwarding push
135 If you provide a _<directory>_, the command is run inside it. If this directory
136 does not exist, it will be created.
141 Files and directories in the template directory whose name do not start with a
142 dot will be copied to the `$GIT_DIR` after it is created.
144 The template directory will be one of the following (in order):
146 - the argument given with the `--template` option;
148 - the contents of the `$GIT_TEMPLATE_DIR` environment variable;
150 - the `init.templateDir` configuration variable; or
152 - the default template directory: `/usr/share/git-core/templates`.
154 The default template directory includes some directory structure, suggested
155 "exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
157 The sample hooks are all disabled by default. To enable one of the
158 sample hooks rename it by removing its `.sample` suffix.
160 See linkgit:githooks[5] for more general info on hook execution.
165 Start a new Git repository for an existing code base::
168 $ cd /path/to/my/codebase
174 <1> Create a `/path/to/my/codebase/.git` directory.
175 <2> Add all existing files to the index.
176 <3> Record the pristine state as the first commit in the history.
181 include::includes/cmd-config-section-all.txt[]
185 include::config/init.txt[]
189 Part of the linkgit:git[1] suite