Raw
1 git-init(1)
2 ===========
3
4 NAME
5 ----
6 git-init - Create an empty Git repository or reinitialize an existing one
7
8
9 SYNOPSIS
10 --------
11 [synopsis]
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>]
17
18
19 DESCRIPTION
20 -----------
21
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
26 for its name).
27
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.
30
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`
34 directory is used.
35
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).
40
41 OPTIONS
42 -------
43
44 `-q`::
45 `--quiet`::
46
47 Only print error and warning messages; all other output will be suppressed.
48
49 `--bare`::
50
51 Create a bare repository. If `GIT_DIR` environment is not set, it is set to the
52 current working directory.
53
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.
57 +
58 include::object-format-disclaimer.adoc[]
59
60 `--ref-format=<format>`::
61 Specify the given ref storage _<format>_ for the repository. The valid values are:
62 +
63 include::ref-storage-format.adoc[]
64
65 `--template=<template-directory>`::
66 Specify the directory from which templates will be used. (See the "TEMPLATE
67 DIRECTORY" section below.)
68
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
73 repository.
74 +
75 If this is a reinitialization, the repository will be moved to the specified path.
76
77 `-b <branch-name>`::
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
81 ifndef::with-breaking-changes[]
82 (currently `master`, but this will change to `main` when Git 3.0 is released).
83 endif::with-breaking-changes[]
84 ifdef::with-breaking-changes[]
85 `main`.
86 endif::with-breaking-changes[]
87 The default name can be customized via the `init.defaultBranch` configuration
88 variable.
89
90 `--shared[=(false|true|umask|group|all|world|everybody|<perm>)]`::
91
92 Specify that the Git repository is to be shared amongst several users. This
93 allows users belonging to the same group to push into that
94 repository. When specified, the config variable `core.sharedRepository` is
95 set so that files and directories under `$GIT_DIR` are created with the
96 requested permissions. When not specified, Git will use permissions reported
97 by `umask`(2).
98 +
99 The option can have the following values, defaulting to `group` if no value
100 is given:
101 +
102 --
103 `umask`::
104 `false`::
105
106 Use permissions reported by `umask`(2). The default, when `--shared` is not
107 specified.
108
109 `group`::
110 `true`::
111
112 Make the repository group-writable, (and `g+sx`, since the git group may not be
113 the primary group of all users). This is used to loosen the permissions of an
114 otherwise safe `umask`(2) value. Note that the umask still applies to the other
115 permission bits (e.g. if umask is `0022`, using `group` will not remove read
116 privileges from other (non-group) users). See `0xxx` for how to exactly specify
117 the repository permissions.
118
119 `all`::
120 `world`::
121 `everybody`::
122
123 Same as `group`, but make the repository readable by all users.
124
125 _<perm>_::
126
127 _<perm>_ is a 3-digit octal number prefixed with `0` and each file
128 will have mode _<perm>_. _<perm>_ will override users' `umask`(2)
129 value (and not only loosen permissions as `group` and `all`
130 do). `0640` will create a repository which is group-readable, but
131 not group-writable or accessible to others. `0660` will create a repo
132 that is readable and writable to the current user and group, but
133 inaccessible to others (directories and executable files get their
134 `x` bit from the `r` bit for corresponding classes of users).
135 --
136
137 By default, the configuration flag `receive.denyNonFastForwards` is enabled
138 in shared repositories, so that you cannot force a non fast-forwarding push
139 into it.
140
141 If you provide a _<directory>_, the command is run inside it. If this directory
142 does not exist, it will be created.
143
144 TEMPLATE DIRECTORY
145 ------------------
146
147 Files and directories in the template directory whose name do not start with a
148 dot will be copied to the `$GIT_DIR` after it is created.
149
150 The template directory will be one of the following (in order):
151
152 - the argument given with the `--template` option;
153
154 - the contents of the `$GIT_TEMPLATE_DIR` environment variable;
155
156 - the `init.templateDir` configuration variable; or
157
158 - the default template directory: `/usr/share/git-core/templates`.
159
160 The default template directory includes some directory structure, suggested
161 "exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
162
163 The sample hooks are all disabled by default. To enable one of the
164 sample hooks rename it by removing its `.sample` suffix.
165
166 See linkgit:githooks[5] for more general info on hook execution.
167
168 EXAMPLES
169 --------
170
171 Start a new Git repository for an existing code base::
172 +
173 ----------------
174 $ cd /path/to/my/codebase
175 $ git init <1>
176 $ git add . <2>
177 $ git commit <3>
178 ----------------
179 +
180 <1> Create a `/path/to/my/codebase/.git` directory.
181 <2> Add all existing files to the index.
182 <3> Record the pristine state as the first commit in the history.
183
184 CONFIGURATION
185 -------------
186
187 include::includes/cmd-config-section-all.adoc[]
188
189 :git-init:
190
191 include::config/init.adoc[]
192
193 GIT
194 ---
195 Part of the linkgit:git[1] suite