Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 1 | git-init(1) |
| 2 | =========== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 6 | git-init - Create an empty Git repository or reinitialize an existing one |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | a03ac86 | 2011-04-02 04:32:29 | [diff] [blame] | 12 | 'git init' [-q | --quiet] [--bare] [--template=<template_directory>] |
Junio C Hamano | a891178 | 2020-07-07 05:35:57 | [diff] [blame] | 13 | [--separate-git-dir <git dir>] [--object-format=<format>] |
| 14 | [-b <branch-name> | --initial-branch=<branch-name>] |
Junio C Hamano | a03ac86 | 2011-04-02 04:32:29 | [diff] [blame] | 15 | [--shared[=<permissions>]] [directory] |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 16 | |
| 17 | |
Junio C Hamano | a03ac86 | 2011-04-02 04:32:29 | [diff] [blame] | 18 | DESCRIPTION |
| 19 | ----------- |
| 20 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 21 | This command creates an empty Git repository - basically a `.git` |
Junio C Hamano | a03ac86 | 2011-04-02 04:32:29 | [diff] [blame] | 22 | directory with subdirectories for `objects`, `refs/heads`, |
| 23 | `refs/tags`, and template files. An initial `HEAD` file that |
| 24 | references the HEAD of the master branch is also created. |
| 25 | |
| 26 | If the `$GIT_DIR` environment variable is set then it specifies a path |
| 27 | to use instead of `./.git` for the base of the repository. |
| 28 | |
| 29 | If the object storage directory is specified via the |
| 30 | `$GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories |
| 31 | are created underneath - otherwise the default `$GIT_DIR/objects` |
| 32 | directory is used. |
| 33 | |
| 34 | Running 'git init' in an existing repository is safe. It will not |
| 35 | overwrite things that are already there. The primary reason for |
| 36 | rerunning 'git init' is to pick up newly added templates (or to move |
| 37 | the repository to another place if --separate-git-dir is given). |
| 38 | |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 39 | OPTIONS |
| 40 | ------- |
| 41 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 42 | -q:: |
| 43 | --quiet:: |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 44 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 45 | Only print error and warning messages; all other output will be suppressed. |
Junio C Hamano | 1d90cb0 | 2007-07-03 07:05:31 | [diff] [blame] | 46 | |
Junio C Hamano | 9e1793f | 2008-06-02 07:31:16 | [diff] [blame] | 47 | --bare:: |
| 48 | |
Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 49 | Create a bare repository. If `GIT_DIR` environment is not set, it is set to the |
Junio C Hamano | 9e1793f | 2008-06-02 07:31:16 | [diff] [blame] | 50 | current working directory. |
| 51 | |
Junio C Hamano | 1291d1a | 2020-03-27 01:15:03 | [diff] [blame] | 52 | --object-format=<format>:: |
| 53 | |
| 54 | Specify the given object format (hash algorithm) for the repository. The valid |
| 55 | values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default. |
Junio C Hamano | 48d7a8a | 2020-08-24 22:56:56 | [diff] [blame] | 56 | + |
| 57 | include::object-format-disclaimer.txt[] |
Junio C Hamano | 1291d1a | 2020-03-27 01:15:03 | [diff] [blame] | 58 | |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 59 | --template=<template_directory>:: |
| 60 | |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 61 | Specify the directory from which templates will be used. (See the "TEMPLATE |
| 62 | DIRECTORY" section below.) |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 63 | |
Junio C Hamano | a03ac86 | 2011-04-02 04:32:29 | [diff] [blame] | 64 | --separate-git-dir=<git dir>:: |
| 65 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 66 | Instead 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 |
| 68 | repository. This file acts as filesystem-agnostic Git symbolic link to the |
| 69 | repository. |
| 70 | + |
| 71 | If this is reinitialization, the repository will be moved to the specified path. |
Junio C Hamano | a03ac86 | 2011-04-02 04:32:29 | [diff] [blame] | 72 | |
Junio C Hamano | cba446b | 2020-10-09 15:51:15 | [diff] [blame] | 73 | -b <branch-name>:: |
Junio C Hamano | a891178 | 2020-07-07 05:35:57 | [diff] [blame] | 74 | --initial-branch=<branch-name>:: |
| 75 | |
| 76 | Use the specified name for the initial branch in the newly created repository. |
| 77 | If not specified, fall back to the default name: `master`. |
| 78 | |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 79 | --shared[=(false|true|umask|group|all|world|everybody|0xxx)]:: |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 80 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 81 | Specify that the Git repository is to be shared amongst several users. This |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 82 | allows users belonging to the same group to push into that |
| 83 | repository. When specified, the config variable "core.sharedRepository" is |
| 84 | set so that files and directories under `$GIT_DIR` are created with the |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 85 | requested permissions. When not specified, Git will use permissions reported |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 86 | by umask(2). |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 87 | + |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 88 | The option can have the following values, defaulting to 'group' if no value |
| 89 | is given: |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 90 | + |
| 91 | -- |
| 92 | 'umask' (or 'false'):: |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 93 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 94 | Use permissions reported by umask(2). The default, when `--shared` is not |
| 95 | specified. |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 96 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 97 | 'group' (or 'true'):: |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 98 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 99 | Make the repository group-writable, (and g+sx, since the git group may be not |
| 100 | the primary group of all users). This is used to loosen the permissions of an |
| 101 | otherwise safe umask(2) value. Note that the umask still applies to the other |
| 102 | permission bits (e.g. if umask is '0022', using 'group' will not remove read |
| 103 | privileges from other (non-group) users). See '0xxx' for how to exactly specify |
| 104 | the repository permissions. |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 105 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 106 | 'all' (or 'world' or 'everybody'):: |
Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 107 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 108 | Same 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 |
| 113 | override 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 |
| 115 | group-writable or accessible to others. '0660' will create a repo that is |
| 116 | readable and writable to the current user and group, but inaccessible to others. |
| 117 | -- |
| 118 | |
| 119 | By default, the configuration flag `receive.denyNonFastForwards` is enabled |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 120 | in shared repositories, so that you cannot force a non fast-forwarding push |
| 121 | into it. |
| 122 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 123 | If you provide a 'directory', the command is run inside it. If this directory |
| 124 | does not exist, it will be created. |
Junio C Hamano | fd9274d | 2009-08-05 21:21:39 | [diff] [blame] | 125 | |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 126 | TEMPLATE DIRECTORY |
| 127 | ------------------ |
| 128 | |
Junio C Hamano | fa0dac3 | 2017-02-24 19:02:55 | [diff] [blame] | 129 | Files and directories in the template directory whose name do not start with a |
| 130 | dot will be copied to the `$GIT_DIR` after it is created. |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 131 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 132 | The template directory will be one of the following (in order): |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 133 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 134 | - the argument given with the `--template` option; |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 135 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 136 | - the contents of the `$GIT_TEMPLATE_DIR` environment variable; |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 137 | |
Junio C Hamano | 322c624 | 2015-03-23 21:32:46 | [diff] [blame] | 138 | - the `init.templateDir` configuration variable; or |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 139 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 140 | - the default template directory: `/usr/share/git-core/templates`. |
Junio C Hamano | caa712a | 2010-03-11 01:17:35 | [diff] [blame] | 141 | |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 142 | The default template directory includes some directory structure, suggested |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 143 | "exclude patterns" (see linkgit:gitignore[5]), and sample hook files. |
| 144 | |
Junio C Hamano | 23168ef | 2019-02-07 07:20:47 | [diff] [blame] | 145 | The sample hooks are all disabled by default. To enable one of the |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 146 | sample hooks rename it by removing its `.sample` suffix. |
| 147 | |
| 148 | See linkgit:githooks[5] for more general info on hook execution. |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 149 | |
| 150 | EXAMPLES |
| 151 | -------- |
| 152 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 153 | Start a new Git repository for an existing code base:: |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 154 | + |
| 155 | ---------------- |
| 156 | $ cd /path/to/my/codebase |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 157 | $ git init <1> |
| 158 | $ git add . <2> |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 159 | $ git commit <3> |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 160 | ---------------- |
| 161 | + |
Junio C Hamano | 53fe031 | 2014-09-09 21:16:17 | [diff] [blame] | 162 | <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 Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 165 | |
Junio C Hamano | 91f77a0 | 2007-01-12 02:43:42 | [diff] [blame] | 166 | GIT |
| 167 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 168 | Part of the linkgit:git[1] suite |