blob: 59ecda6c17d0125716e3ed108fa5935a4327a3fc [file] [log] [blame]
Junio C Hamano91f77a02007-01-12 02:43:421git-init(1)
2===========
3
4NAME
5----
Junio C Hamano076ffcc2013-02-06 05:13:216git-init - Create an empty Git repository or reinitialize an existing one
Junio C Hamano91f77a02007-01-12 02:43:427
8
9SYNOPSIS
10--------
Junio C Hamano15567bc2011-07-23 00:51:5911[verse]
Junio C Hamanoa03ac862011-04-02 04:32:2912'git init' [-q | --quiet] [--bare] [--template=<template_directory>]
Junio C Hamanoa8911782020-07-07 05:35:5713 [--separate-git-dir <git dir>] [--object-format=<format>]
14 [-b <branch-name> | --initial-branch=<branch-name>]
Junio C Hamanoa03ac862011-04-02 04:32:2915 [--shared[=<permissions>]] [directory]
Junio C Hamano91f77a02007-01-12 02:43:4216
17
Junio C Hamanoa03ac862011-04-02 04:32:2918DESCRIPTION
19-----------
20
Junio C Hamano076ffcc2013-02-06 05:13:2121This command creates an empty Git repository - basically a `.git`
Junio C Hamanoa03ac862011-04-02 04:32:2922directory with subdirectories for `objects`, `refs/heads`,
23`refs/tags`, and template files. An initial `HEAD` file that
24references the HEAD of the master branch is also created.
25
26If the `$GIT_DIR` environment variable is set then it specifies a path
27to use instead of `./.git` for the base of the repository.
28
29If the object storage directory is specified via the
30`$GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories
31are created underneath - otherwise the default `$GIT_DIR/objects`
32directory is used.
33
34Running 'git init' in an existing repository is safe. It will not
35overwrite things that are already there. The primary reason for
36rerunning 'git init' is to pick up newly added templates (or to move
37the repository to another place if --separate-git-dir is given).
38
Junio C Hamano91f77a02007-01-12 02:43:4239OPTIONS
40-------
41
Junio C Hamanoeb415992008-06-08 22:49:4742-q::
43--quiet::
Junio C Hamano1d90cb02007-07-03 07:05:3144
Junio C Hamano53fe0312014-09-09 21:16:1745Only print error and warning messages; all other output will be suppressed.
Junio C Hamano1d90cb02007-07-03 07:05:3146
Junio C Hamano9e1793f2008-06-02 07:31:1647--bare::
48
Junio C Hamano042f2142016-06-27 18:05:0549Create a bare repository. If `GIT_DIR` environment is not set, it is set to the
Junio C Hamano9e1793f2008-06-02 07:31:1650current working directory.
51
Junio C Hamano1291d1a2020-03-27 01:15:0352--object-format=<format>::
53
54Specify the given object format (hash algorithm) for the repository. The valid
55values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default.
Junio C Hamano48d7a8a2020-08-24 22:56:5656+
57include::object-format-disclaimer.txt[]
Junio C Hamano1291d1a2020-03-27 01:15:0358
Junio C Hamano91f77a02007-01-12 02:43:4259--template=<template_directory>::
60
Junio C Hamanocaa712a2010-03-11 01:17:3561Specify the directory from which templates will be used. (See the "TEMPLATE
62DIRECTORY" section below.)
Junio C Hamano91f77a02007-01-12 02:43:4263
Junio C Hamanoa03ac862011-04-02 04:32:2964--separate-git-dir=<git dir>::
65
Junio C Hamano53fe0312014-09-09 21:16:1766Instead of initializing the repository as a directory to either `$GIT_DIR` or
67`./.git/`, create a text file there containing the path to the actual
68repository. This file acts as filesystem-agnostic Git symbolic link to the
69repository.
70+
71If this is reinitialization, the repository will be moved to the specified path.
Junio C Hamanoa03ac862011-04-02 04:32:2972
Junio C Hamanocba446b2020-10-09 15:51:1573-b <branch-name>::
Junio C Hamanoa8911782020-07-07 05:35:5774--initial-branch=<branch-name>::
75
76Use the specified name for the initial branch in the newly created repository.
77If not specified, fall back to the default name: `master`.
78
Junio C Hamanod2179ef2010-10-22 04:12:1779--shared[=(false|true|umask|group|all|world|everybody|0xxx)]::
Junio C Hamano91f77a02007-01-12 02:43:4280
Junio C Hamano076ffcc2013-02-06 05:13:2181Specify that the Git repository is to be shared amongst several users. This
Junio C Hamano91f77a02007-01-12 02:43:4282allows users belonging to the same group to push into that
83repository. When specified, the config variable "core.sharedRepository" is
84set so that files and directories under `$GIT_DIR` are created with the
Junio C Hamano076ffcc2013-02-06 05:13:2185requested permissions. When not specified, Git will use permissions reported
Junio C Hamano91f77a02007-01-12 02:43:4286by umask(2).
Junio C Hamano53fe0312014-09-09 21:16:1787+
Junio C Hamano91f77a02007-01-12 02:43:4288The option can have the following values, defaulting to 'group' if no value
89is given:
Junio C Hamano53fe0312014-09-09 21:16:1790+
91--
92'umask' (or 'false')::
Junio C Hamano91f77a02007-01-12 02:43:4293
Junio C Hamano53fe0312014-09-09 21:16:1794Use permissions reported by umask(2). The default, when `--shared` is not
95specified.
Junio C Hamano91f77a02007-01-12 02:43:4296
Junio C Hamano53fe0312014-09-09 21:16:1797'group' (or 'true')::
Junio C Hamano91f77a02007-01-12 02:43:4298
Junio C Hamano53fe0312014-09-09 21:16:1799Make the repository group-writable, (and g+sx, since the git group may be not
100the primary group of all users). This is used to loosen the permissions of an
101otherwise safe umask(2) value. Note that the umask still applies to the other
102permission bits (e.g. if umask is '0022', using 'group' will not remove read
103privileges from other (non-group) users). See '0xxx' for how to exactly specify
104the repository permissions.
Junio C Hamano91f77a02007-01-12 02:43:42105
Junio C Hamano53fe0312014-09-09 21:16:17106'all' (or 'world' or 'everybody')::
Junio C Hamano2f102bb2008-04-26 02:23:37107
Junio C Hamano53fe0312014-09-09 21:16:17108Same as 'group', but make the repository readable by all users.
109
110'0xxx'::
111
112'0xxx' is an octal number and each file will have mode '0xxx'. '0xxx' will
113override users' umask(2) value (and not only loosen permissions as 'group' and
114'all' does). '0640' will create a repository which is group-readable, but not
115group-writable or accessible to others. '0660' will create a repo that is
116readable and writable to the current user and group, but inaccessible to others.
117--
118
119By default, the configuration flag `receive.denyNonFastForwards` is enabled
Junio C Hamano91f77a02007-01-12 02:43:42120in shared repositories, so that you cannot force a non fast-forwarding push
121into it.
122
Junio C Hamano53fe0312014-09-09 21:16:17123If you provide a 'directory', the command is run inside it. If this directory
124does not exist, it will be created.
Junio C Hamanofd9274d2009-08-05 21:21:39125
Junio C Hamanocaa712a2010-03-11 01:17:35126TEMPLATE DIRECTORY
127------------------
128
Junio C Hamanofa0dac32017-02-24 19:02:55129Files and directories in the template directory whose name do not start with a
130dot will be copied to the `$GIT_DIR` after it is created.
Junio C Hamanocaa712a2010-03-11 01:17:35131
Junio C Hamano53fe0312014-09-09 21:16:17132The template directory will be one of the following (in order):
Junio C Hamanocaa712a2010-03-11 01:17:35133
Junio C Hamano53fe0312014-09-09 21:16:17134 - the argument given with the `--template` option;
Junio C Hamanocaa712a2010-03-11 01:17:35135
Junio C Hamano53fe0312014-09-09 21:16:17136 - the contents of the `$GIT_TEMPLATE_DIR` environment variable;
Junio C Hamanocaa712a2010-03-11 01:17:35137
Junio C Hamano322c6242015-03-23 21:32:46138 - the `init.templateDir` configuration variable; or
Junio C Hamanocaa712a2010-03-11 01:17:35139
Junio C Hamano53fe0312014-09-09 21:16:17140 - the default template directory: `/usr/share/git-core/templates`.
Junio C Hamanocaa712a2010-03-11 01:17:35141
Junio C Hamano53fe0312014-09-09 21:16:17142The default template directory includes some directory structure, suggested
Junio C Hamano198b1f12016-05-17 22:27:24143"exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
144
Junio C Hamano23168ef2019-02-07 07:20:47145The sample hooks are all disabled by default. To enable one of the
Junio C Hamano198b1f12016-05-17 22:27:24146sample hooks rename it by removing its `.sample` suffix.
147
148See linkgit:githooks[5] for more general info on hook execution.
Junio C Hamano91f77a02007-01-12 02:43:42149
150EXAMPLES
151--------
152
Junio C Hamano076ffcc2013-02-06 05:13:21153Start a new Git repository for an existing code base::
Junio C Hamano91f77a02007-01-12 02:43:42154+
155----------------
156$ cd /path/to/my/codebase
Junio C Hamanofce7c7e2008-07-02 03:06:38157$ git init <1>
158$ git add . <2>
Junio C Hamano53fe0312014-09-09 21:16:17159$ git commit <3>
Junio C Hamano91f77a02007-01-12 02:43:42160----------------
161+
Junio C Hamano53fe0312014-09-09 21:16:17162<1> Create a /path/to/my/codebase/.git directory.
163<2> Add all existing files to the index.
164<3> Record the pristine state as the first commit in the history.
Junio C Hamano91f77a02007-01-12 02:43:42165
Junio C Hamano91f77a02007-01-12 02:43:42166GIT
167---
Junio C Hamanof7c042d2008-06-06 22:50:53168Part of the linkgit:git[1] suite