]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-init.txt
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / Documentation / git-init.txt
CommitLineData
d145144c
JH
1git-init(1)
2===========
3
4NAME
5----
2de9b711 6git-init - Create an empty Git repository or reinitialize an existing one
d145144c
JH
7
8
9SYNOPSIS
10--------
7791a1d9 11[verse]
133db54d
JNA
12'git init' [-q | --quiet] [--bare] [--template=<template-directory>]
13 [--separate-git-dir <git-dir>] [--object-format=<format>]
32ba12da 14 [-b <branch-name> | --initial-branch=<branch-name>]
49cbad0e 15 [--shared[=<permissions>]] [<directory>]
d145144c
JH
16
17
9d379f4f
NTND
18DESCRIPTION
19-----------
20
2de9b711 21This command creates an empty Git repository - basically a `.git`
9d379f4f 22directory with subdirectories for `objects`, `refs/heads`,
1296cbe4
JS
23`refs/tags`, and template files. An initial branch without any
24commits will be created (see the `--initial-branch` option below
25for its name).
9d379f4f
NTND
26
27If the `$GIT_DIR` environment variable is set then it specifies a path
28to use instead of `./.git` for the base of the repository.
29
30If the object storage directory is specified via the
31`$GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories
32are created underneath - otherwise the default `$GIT_DIR/objects`
33directory is used.
34
35Running 'git init' in an existing repository is safe. It will not
36overwrite things that are already there. The primary reason for
b57fb80a
NTND
37rerunning 'git init' is to pick up newly added templates (or to move
38the repository to another place if --separate-git-dir is given).
9d379f4f 39
d145144c
JH
40OPTIONS
41-------
42
3240240f
SB
43-q::
44--quiet::
4576518d 45
6e1ccacb 46Only print error and warning messages; all other output will be suppressed.
4576518d 47
74d3b23f
LR
48--bare::
49
47d81b5c 50Create a bare repository. If `GIT_DIR` environment is not set, it is set to the
74d3b23f
LR
51current working directory.
52
8b8f7189 53--object-format=<format>::
54
55Specify the given object format (hash algorithm) for the repository. The valid
56values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default.
ff233d8d
57+
58include::object-format-disclaimer.txt[]
8b8f7189 59
133db54d 60--template=<template-directory>::
d145144c 61
d8a8488d
SD
62Specify the directory from which templates will be used. (See the "TEMPLATE
63DIRECTORY" section below.)
d145144c 64
133db54d 65--separate-git-dir=<git-dir>::
b57fb80a 66
c165d1f5
LA
67Instead of initializing the repository as a directory to either `$GIT_DIR` or
68`./.git/`, create a text file there containing the path to the actual
69repository. This file acts as filesystem-agnostic Git symbolic link to the
70repository.
71+
72If this is reinitialization, the repository will be moved to the specified path.
b57fb80a 73
9f443f55 74-b <branch-name>::
32ba12da
JS
75--initial-branch=<branch-name>::
76
1296cbe4
JS
77Use the specified name for the initial branch in the newly created
78repository. If not specified, fall back to the default name (currently
79`master`, but this is subject to change in the future; the name can be
80customized via the `init.defaultBranch` configuration variable).
32ba12da 81
f9b2b668 82--shared[=(false|true|umask|group|all|world|everybody|<perm>)]::
d145144c 83
2de9b711 84Specify that the Git repository is to be shared amongst several users. This
d145144c
JH
85allows users belonging to the same group to push into that
86repository. When specified, the config variable "core.sharedRepository" is
87set so that files and directories under `$GIT_DIR` are created with the
2de9b711 88requested permissions. When not specified, Git will use permissions reported
d145144c 89by umask(2).
ddeab3ae 90+
d145144c
JH
91The option can have the following values, defaulting to 'group' if no value
92is given:
ddeab3ae
LA
93+
94--
95'umask' (or 'false')::
96
97Use permissions reported by umask(2). The default, when `--shared` is not
98specified.
99
100'group' (or 'true')::
101
102Make the repository group-writable, (and g+sx, since the git group may be not
103the primary group of all users). This is used to loosen the permissions of an
104otherwise safe umask(2) value. Note that the umask still applies to the other
105permission bits (e.g. if umask is '0022', using 'group' will not remove read
106privileges from other (non-group) users). See '0xxx' for how to exactly specify
107the repository permissions.
d145144c 108
ddeab3ae
LA
109'all' (or 'world' or 'everybody')::
110
111Same as 'group', but make the repository readable by all users.
112
f9b2b668 113'<perm>'::
ddeab3ae 114
f9b2b668
JH
115'<perm>' is a 3-digit octal number prefixed with `0` and each file
116will have mode '<perm>'. '<perm>' will override users' umask(2)
b7088a5f
JNA
117value (and not only loosen permissions as 'group' and 'all'
118does). '0640' will create a repository which is group-readable, but
119not group-writable or accessible to others. '0660' will create a repo
120that is readable and writable to the current user and group, but
f9b2b668
JH
121inaccessible to others (directories and executable files get their
122`x` bit from the `r` bit for corresponding classes of users).
ddeab3ae 123--
06cbe855 124
6e1ccacb 125By default, the configuration flag `receive.denyNonFastForwards` is enabled
d145144c
JH
126in shared repositories, so that you cannot force a non fast-forwarding push
127into it.
128
4dde849a
LA
129If you provide a 'directory', the command is run inside it. If this directory
130does not exist, it will be created.
53d48885 131
d8a8488d
SD
132TEMPLATE DIRECTORY
133------------------
134
133f0a29
GP
135Files and directories in the template directory whose name do not start with a
136dot will be copied to the `$GIT_DIR` after it is created.
d8a8488d 137
86d387af 138The template directory will be one of the following (in order):
d8a8488d 139
86d387af 140 - the argument given with the `--template` option;
d8a8488d 141
86d387af 142 - the contents of the `$GIT_TEMPLATE_DIR` environment variable;
d8a8488d 143
da0005b8 144 - the `init.templateDir` configuration variable; or
d8a8488d 145
86d387af 146 - the default template directory: `/usr/share/git-core/templates`.
d8a8488d 147
8994fbf3 148The default template directory includes some directory structure, suggested
49fa52fd
ÆAB
149"exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
150
86fb1c4e 151The sample hooks are all disabled by default. To enable one of the
49fa52fd
ÆAB
152sample hooks rename it by removing its `.sample` suffix.
153
154See linkgit:githooks[5] for more general info on hook execution.
d145144c
JH
155
156EXAMPLES
157--------
158
2de9b711 159Start a new Git repository for an existing code base::
d145144c
JH
160+
161----------------
162$ cd /path/to/my/codebase
b1889c36
JN
163$ git init <1>
164$ git add . <2>
64de2e10 165$ git commit <3>
d145144c
JH
166----------------
167+
6e1ccacb
LA
168<1> Create a /path/to/my/codebase/.git directory.
169<2> Add all existing files to the index.
64de2e10 170<3> Record the pristine state as the first commit in the history.
d145144c 171
d145144c
JH
172GIT
173---
9e1f0a85 174Part of the linkgit:git[1] suite