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 THIS OPTION IS EXPERIMENTAL! SHA-256 support is experimental and
49 still in an early stage. A SHA-256 repository will in general not
50 be able to share work with "regular" SHA-1 repositories. It should
51 be assumed that, e.g., Git internal file formats in relation to
52 SHA-256 repositories may change in backwards-incompatible ways.
53 Only use --object-format=sha256 for testing purposes.
54
55 --template=<template-directory>
56 Specify the directory from which templates will be used. (See the
57 "TEMPLATE DIRECTORY" section below.)
58
59 --separate-git-dir=<git-dir>
60 Instead of initializing the repository as a directory to either
61 $GIT_DIR or ./.git/, create a text file there containing the path
62 to the actual repository. This file acts as filesystem-agnostic Git
63 symbolic link to the repository.
64
65 If this is reinitialization, the repository will be moved to the
66 specified path.
67
68 -b <branch-name>, --initial-branch=<branch-name>
69 Use the specified name for the initial branch in the newly created
70 repository. If not specified, fall back to the default name
71 (currently master, but this is subject to change in the future; the
72 name can be customized via the init.defaultBranch configuration
73 variable).
74
75 --shared[=(false|true|umask|group|all|world|everybody|<perm>)]
76 Specify that the Git repository is to be shared amongst several
77 users. This allows users belonging to the same group to push into
78 that repository. When specified, the config variable
79 "core.sharedRepository" is set so that files and directories under
80 $GIT_DIR are created with the requested permissions. When not
81 specified, Git will use permissions reported by umask(2).
82
83 The option can have the following values, defaulting to group if no
84 value is given:
85
86 umask (or false)
87 Use permissions reported by umask(2). The default, when
88 --shared is not specified.
89
90 group (or true)
91 Make the repository group-writable, (and g+sx, since the git
92 group may be not the primary group of all users). This is used
93 to loosen the permissions of an otherwise safe umask(2) value.
94 Note that the umask still applies to the other permission bits
95 (e.g. if umask is 0022, using group will not remove read
96 privileges from other (non-group) users). See 0xxx for how to
97 exactly specify the repository permissions.
98
99 all (or world or everybody)
100 Same as group, but make the repository readable by all users.
101
102 <perm>
103 <perm> is a 3-digit octal number prefixed with 0 and each file
104 will have mode <perm>. <perm> will override users' umask(2)
105 value (and not only loosen permissions as group and all does).
106 0640 will create a repository which is group-readable, but not
107 group-writable or accessible to others. 0660 will create a
108 repo that is readable and writable to the current user and
109 group, but inaccessible to others (directories and executable
110 files get their x bit from the r bit for corresponding classes
111 of users).
112
113 By default, the configuration flag receive.denyNonFastForwards is
114 enabled in shared repositories, so that you cannot force a non
115 fast-forwarding push into it.
116
117 If you provide a directory, the command is run inside it. If this
118 directory does not exist, it will be created.
119
121 Files and directories in the template directory whose name do not start
122 with a dot will be copied to the $GIT_DIR after it is created.
123
124 The template directory will be one of the following (in order):
125
126 • the argument given with the --template option;
127
128 • the contents of the $GIT_TEMPLATE_DIR environment variable;
129
130 • the init.templateDir configuration variable; or
131
132 • the default template directory: /usr/share/git-core/templates.
133
134 The default template directory includes some directory structure,
135 suggested "exclude patterns" (see gitignore(5)), and sample hook files.
136
137 The sample hooks are all disabled by default. To enable one of the
138 sample hooks rename it by removing its .sample suffix.
139
140 See githooks(5) for more general info on hook execution.
141
143 Start a new Git repository for an existing code base
144
145 $ cd /path/to/my/codebase
146 $ git init [1m(1)
147 $ git add . [1m(2)
148 $ git commit [1m(3)
149
150 1. Create a /path/to/my/codebase/.git directory.
151 2. Add all existing files to the index.
152 3. Record the pristine state as the first commit in the
153 history.
154
156 Part of the git(1) suite
157
158
159
160Git 2.36.1 2022-05-05 GIT-INIT(1)