Git fork
1git-init(1)
2===========
3
4NAME
5----
6git-init - Create an empty Git repository or reinitialize an existing one
7
8
9SYNOPSIS
10--------
11[synopsis]
12git 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
19DESCRIPTION
20-----------
21
22This command creates an empty Git repository - basically a `.git`
23directory with subdirectories for `objects`, `refs/heads`,
24`refs/tags`, and template files. An initial branch without any
25commits will be created (see the `--initial-branch` option below
26for its name).
27
28If the `GIT_DIR` environment variable is set then it specifies a path
29to use instead of `./.git` for the base of the repository.
30
31If the object storage directory is specified via the
32`GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories
33are created underneath; otherwise, the default `$GIT_DIR/objects`
34directory is used.
35
36Running `git init` in an existing repository is safe. It will not
37overwrite things that are already there. The primary reason for
38rerunning `git init` is to pick up newly added templates (or to move
39the repository to another place if `--separate-git-dir` is given).
40
41OPTIONS
42-------
43
44`-q`::
45`--quiet`::
46
47Only print error and warning messages; all other output will be suppressed.
48
49`--bare`::
50
51Create a bare repository. If `GIT_DIR` environment is not set, it is set to the
52current working directory.
53
54`--object-format=<format>`::
55Specify the given object _<format>_ (hash algorithm) for the repository. The valid
56values are `sha1` and (if enabled) `sha256`. `sha1` is the default.
57+
58include::object-format-disclaimer.adoc[]
59
60`--ref-format=<format>`::
61Specify the given ref storage _<format>_ for the repository. The valid values are:
62+
63include::ref-storage-format.adoc[]
64
65`--template=<template-directory>`::
66Specify the directory from which templates will be used. (See the "TEMPLATE
67DIRECTORY" section below.)
68
69`--separate-git-dir=<git-dir>`::
70Instead 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
72repository. This file acts as a filesystem-agnostic Git symbolic link to the
73repository.
74+
75If this is a reinitialization, the repository will be moved to the specified path.
76
77`-b <branch-name>`::
78`--initial-branch=<branch-name>`::
79Use _<branch-name>_ for the initial branch in the newly created
80repository. If not specified, fall back to the default name
81ifndef::with-breaking-changes[]
82(currently `master`, but this will change to `main` when Git 3.0 is released).
83endif::with-breaking-changes[]
84ifdef::with-breaking-changes[]
85`main`.
86endif::with-breaking-changes[]
87The default name can be customized via the `init.defaultBranch` configuration
88variable.
89
90`--shared[=(false|true|umask|group|all|world|everybody|<perm>)]`::
91
92Specify that the Git repository is to be shared amongst several users. This
93allows users belonging to the same group to push into that
94repository. When specified, the config variable `core.sharedRepository` is
95set so that files and directories under `$GIT_DIR` are created with the
96requested permissions. When not specified, Git will use permissions reported
97by `umask`(2).
98+
99The option can have the following values, defaulting to `group` if no value
100is given:
101+
102--
103`umask`::
104`false`::
105
106Use permissions reported by `umask`(2). The default, when `--shared` is not
107specified.
108
109`group`::
110`true`::
111
112Make the repository group-writable, (and `g+sx`, since the git group may not be
113the primary group of all users). This is used to loosen the permissions of an
114otherwise safe `umask`(2) value. Note that the umask still applies to the other
115permission bits (e.g. if umask is `0022`, using `group` will not remove read
116privileges from other (non-group) users). See `0xxx` for how to exactly specify
117the repository permissions.
118
119`all`::
120`world`::
121`everybody`::
122
123Same 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
128will have mode _<perm>_. _<perm>_ will override users' `umask`(2)
129value (and not only loosen permissions as `group` and `all`
130do). `0640` will create a repository which is group-readable, but
131not group-writable or accessible to others. `0660` will create a repo
132that is readable and writable to the current user and group, but
133inaccessible to others (directories and executable files get their
134`x` bit from the `r` bit for corresponding classes of users).
135--
136
137By default, the configuration flag `receive.denyNonFastForwards` is enabled
138in shared repositories, so that you cannot force a non fast-forwarding push
139into it.
140
141If you provide a _<directory>_, the command is run inside it. If this directory
142does not exist, it will be created.
143
144TEMPLATE DIRECTORY
145------------------
146
147Files and directories in the template directory whose name do not start with a
148dot will be copied to the `$GIT_DIR` after it is created.
149
150The 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
160The default template directory includes some directory structure, suggested
161"exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
162
163The sample hooks are all disabled by default. To enable one of the
164sample hooks rename it by removing its `.sample` suffix.
165
166See linkgit:githooks[5] for more general info on hook execution.
167
168EXAMPLES
169--------
170
171Start 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
184CONFIGURATION
185-------------
186
187include::includes/cmd-config-section-all.adoc[]
188
189:git-init:
190
191include::config/init.adoc[]
192
193GIT
194---
195Part of the linkgit:git[1] suite