1GIT-INIT(1) Git Manual GIT-INIT(1)
2
3
4
6 git-init - Create an empty Git repository or reinitialize an existing
7 one
8
10 git init [-q | --quiet] [--bare] [--template=<template-directory>]
11 [--separate-git-dir <git-dir>] [--object-format=<format>]
12 [-b <branch-name> | --initial-branch=<branch-name>]
13 [--shared[=<permissions>]] [<directory>]
14
16 This command creates an empty Git repository - basically a .git
17 directory with subdirectories for objects, refs/heads, refs/tags, and
18 template files. An initial branch without any commits will be created
19 (see the --initial-branch option below for its name).
20
21 If the $GIT_DIR environment variable is set then it specifies a path to
22 use instead of ./.git for the base of the repository.
23
24 If the object storage directory is specified via the
25 $GIT_OBJECT_DIRECTORY environment variable then the sha1 directories
26 are created underneath; otherwise, the default $GIT_DIR/objects
27 directory is used.
28
29 Running git init in an existing repository is safe. It will not
30 overwrite things that are already there. The primary reason for
31 rerunning git init is to pick up newly added templates (or to move the
32 repository to another place if --separate-git-dir is given).
33
35 -q, --quiet
36 Only print error and warning messages; all other output will be
37 suppressed.
38
39 --bare
40 Create a bare repository. If GIT_DIR environment is not set, it is
41 set to the current working directory.
42
43 --object-format=<format>
44 Specify the given object format (hash algorithm) for the
45 repository. The valid values are sha1 and (if enabled) sha256.
46 sha1 is the default.
47
48 Note: At present, there is no interoperability between SHA-256
49 repositories and SHA-1 repositories.
50
51 Historically, we warned that SHA-256 repositories may later need
52 backward incompatible changes when we introduce such interoperability
53 features. Today, we only expect compatible changes. Furthermore, if
54 such changes prove to be necessary, it can be expected that SHA-256
55 repositories created with today’s Git will be usable by future versions
56 of Git without data loss.
57
58 --template=<template-directory>
59 Specify the directory from which templates will be used. (See the
60 "TEMPLATE DIRECTORY" section below.)
61
62 --separate-git-dir=<git-dir>
63 Instead of initializing the repository as a directory to either
64 $GIT_DIR or ./.git/, create a text file there containing the path
65 to the actual repository. This file acts as a filesystem-agnostic
66 Git symbolic link to the repository.
67
68 If this is a reinitialization, the repository will be moved to the
69 specified path.
70
71 -b <branch-name>, --initial-branch=<branch-name>
72 Use the specified name for the initial branch in the newly created
73 repository. If not specified, fall back to the default name
74 (currently master, but this is subject to change in the future; the
75 name can be customized via the init.defaultBranch configuration
76 variable).
77
78 --shared[=(false|true|umask|group|all|world|everybody|<perm>)]
79 Specify that the Git repository is to be shared amongst several
80 users. This allows users belonging to the same group to push into
81 that repository. When specified, the config variable
82 "core.sharedRepository" is set so that files and directories under
83 $GIT_DIR are created with the requested permissions. When not
84 specified, Git will use permissions reported by umask(2).
85
86 The option can have the following values, defaulting to group if no
87 value is given:
88
89 umask (or false)
90 Use permissions reported by umask(2). The default, when
91 --shared is not specified.
92
93 group (or true)
94 Make the repository group-writable, (and g+sx, since the git
95 group may not be the primary group of all users). This is used
96 to loosen the permissions of an otherwise safe umask(2) value.
97 Note that the umask still applies to the other permission bits
98 (e.g. if umask is 0022, using group will not remove read
99 privileges from other (non-group) users). See 0xxx for how to
100 exactly specify the repository permissions.
101
102 all (or world or everybody)
103 Same as group, but make the repository readable by all users.
104
105 <perm>
106 <perm> is a 3-digit octal number prefixed with 0 and each file
107 will have mode <perm>. <perm> will override users' umask(2)
108 value (and not only loosen permissions as group and all do).
109 0640 will create a repository which is group-readable, but not
110 group-writable or accessible to others. 0660 will create a
111 repo that is readable and writable to the current user and
112 group, but inaccessible to others (directories and executable
113 files get their x bit from the r bit for corresponding classes
114 of users).
115
116 By default, the configuration flag receive.denyNonFastForwards is
117 enabled in shared repositories, so that you cannot force a non
118 fast-forwarding push into it.
119
120 If you provide a directory, the command is run inside it. If this
121 directory does not exist, it will be created.
122
124 Files and directories in the template directory whose name do not start
125 with a dot will be copied to the $GIT_DIR after it is created.
126
127 The template directory will be one of the following (in order):
128
129 • the argument given with the --template option;
130
131 • the contents of the $GIT_TEMPLATE_DIR environment variable;
132
133 • the init.templateDir configuration variable; or
134
135 • the default template directory: /usr/share/git-core/templates.
136
137 The default template directory includes some directory structure,
138 suggested "exclude patterns" (see gitignore(5)), and sample hook files.
139
140 The sample hooks are all disabled by default. To enable one of the
141 sample hooks rename it by removing its .sample suffix.
142
143 See githooks(5) for more general info on hook execution.
144
146 Start a new Git repository for an existing code base
147
148 $ cd /path/to/my/codebase
149 $ git init [1m(1)
150 $ git add . [1m(2)
151 $ git commit [1m(3)
152
153 1. Create a /path/to/my/codebase/.git directory.
154 2. Add all existing files to the index.
155 3. Record the pristine state as the first commit in the
156 history.
157
159 Everything below this line in this section is selectively included from
160 the git-config(1) documentation. The content is the same as what’s
161 found there:
162
163 init.templateDir
164 Specify the directory from which templates will be copied. (See the
165 "TEMPLATE DIRECTORY" section of git-init(1).)
166
167 init.defaultBranch
168 Allows overriding the default branch name e.g. when initializing a
169 new repository.
170
172 Part of the git(1) suite
173
174
175
176Git 2.43.0 11/20/2023 GIT-INIT(1)