1
2
3
4
5
6
7
8
9
10
11
12
|
<h1>git-init</h1> <h2 id="_name">Name</h2> <div class="sectionbody"> <p>git-init - Create an empty Git repository or reinitialize an existing one</p> </div> <h2 id="_synopsis">Synopsis</h2> <div class="sectionbody"> <div class="verseblock"> <pre class="content" data-language="shell">git init [-q | --quiet] [--bare] [--template=<template-directory>]
[--separate-git-dir <git-dir>] [--object-format=<format>]
[-b <branch-name> | --initial-branch=<branch-name>]
[--shared[=<permissions>]] [<directory>]</pre> </div> </div> <h2 id="_description">Description</h2> <div class="sectionbody"> <p>This command creates an empty Git repository - basically a <code>.git</code> directory with subdirectories for <code>objects</code>, <code>refs/heads</code>, <code>refs/tags</code>, and template files. An initial branch without any commits will be created (see the <code>--initial-branch</code> option below for its name).</p> <p>If the <code>$GIT_DIR</code> environment variable is set then it specifies a path to use instead of <code>./.git</code> for the base of the repository.</p> <p>If the object storage directory is specified via the <code>$GIT_OBJECT_DIRECTORY</code> environment variable then the sha1 directories are created underneath; otherwise, the default <code>$GIT_DIR/objects</code> directory is used.</p> <p>Running <code>git init</code> in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning <code>git init</code> is to pick up newly added templates (or to move the repository to another place if --separate-git-dir is given).</p> </div> <h2 id="_options">Options</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-init.txt--q"> -q </dt> <dt class="hdlist1" id="Documentation/git-init.txt---quiet"> --quiet </dt> <dd> <p>Only print error and warning messages; all other output will be suppressed.</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt---bare"> --bare </dt> <dd> <p>Create a bare repository. If <code>GIT_DIR</code> environment is not set, it is set to the current working directory.</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt---object-formatltformatgt"> --object-format=<format> </dt> <dd> <p>Specify the given object format (hash algorithm) for the repository. The valid values are <code>sha1</code> and (if enabled) <code>sha256</code>. <code>sha1</code> is the default.</p> <p>Note: At present, there is no interoperability between SHA-256 repositories and SHA-1 repositories.</p> </dd> </dl> </div> <p>Historically, we warned that SHA-256 repositories may later need backward incompatible changes when we introduce such interoperability features. Today, we only expect compatible changes. Furthermore, if such changes prove to be necessary, it can be expected that SHA-256 repositories created with today’s Git will be usable by future versions of Git without data loss.</p> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-init.txt---templatelttemplate-directorygt"> --template=<template-directory> </dt> <dd> <p>Specify the directory from which templates will be used. (See the "TEMPLATE DIRECTORY" section below.)</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt---separate-git-dirltgit-dirgt"> --separate-git-dir=<git-dir> </dt> <dd> <p>Instead of initializing the repository as a directory to either <code>$GIT_DIR</code> or <code>./.git/</code>, create a text file there containing the path to the actual repository. This file acts as a filesystem-agnostic Git symbolic link to the repository.</p> <p>If this is a reinitialization, the repository will be moved to the specified path.</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt--bltbranch-namegt"> -b <branch-name> </dt> <dt class="hdlist1" id="Documentation/git-init.txt---initial-branchltbranch-namegt"> --initial-branch=<branch-name> </dt> <dd> <p>Use the specified name for the initial branch in the newly created repository. If not specified, fall back to the default name (currently <code>master</code>, but this is subject to change in the future; the name can be customized via the <code>init.defaultBranch</code> configuration variable).</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt---sharedfalsetrueumaskgroupallworldeverybodyltpermgt"> --shared[=(false|true|umask|group|all|world|everybody|<perm>)] </dt> <dd> <p>Specify that the Git repository is to be shared amongst several users. This allows users belonging to the same group to push into that repository. When specified, the config variable "core.sharedRepository" is set so that files and directories under <code>$GIT_DIR</code> are created with the requested permissions. When not specified, Git will use permissions reported by umask(2).</p> <p>The option can have the following values, defaulting to <code>group</code> if no value is given:</p> <div class="openblock"> <div class="content"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-init.txt-emumaskemoremfalseem"> <em>umask</em> (or <em>false</em>) </dt> <dd> <p>Use permissions reported by umask(2). The default, when <code>--shared</code> is not specified.</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt-emgroupemoremtrueem"> <em>group</em> (or <em>true</em>) </dt> <dd> <p>Make the repository group-writable, (and g+sx, since the git group may not be the primary group of all users). This is used to loosen the permissions of an otherwise safe umask(2) value. Note that the umask still applies to the other permission bits (e.g. if umask is <code>0022</code>, using <code>group</code> will not remove read privileges from other (non-group) users). See <code>0xxx</code> for how to exactly specify the repository permissions.</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt-emallemoremworldemoremeverybodyem"> <em>all</em> (or <em>world</em> or <em>everybody</em>) </dt> <dd> <p>Same as <code>group</code>, but make the repository readable by all users.</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt-emltpermgtem"> <em><perm></em> </dt> <dd> <p><code><perm></code> is a 3-digit octal number prefixed with <code>0</code> and each file will have mode <code><perm></code>. <code><perm></code> will override users' umask(2) value (and not only loosen permissions as <code>group</code> and <code>all</code> do). <code>0640</code> will create a repository which is group-readable, but not group-writable or accessible to others. <code>0660</code> will create a repo that is readable and writable to the current user and group, but inaccessible to others (directories and executable files get their <code>x</code> bit from the <code>r</code> bit for corresponding classes of users).</p> </dd> </dl> </div> </div> </div> </dd> </dl> </div> <p>By default, the configuration flag <code>receive.denyNonFastForwards</code> is enabled in shared repositories, so that you cannot force a non fast-forwarding push into it.</p> <p>If you provide a <code>directory</code>, the command is run inside it. If this directory does not exist, it will be created.</p> </div> <h2 id="_template_directory">Template directory</h2> <div class="sectionbody"> <p>Files and directories in the template directory whose name do not start with a dot will be copied to the <code>$GIT_DIR</code> after it is created.</p> <p>The template directory will be one of the following (in order):</p> <div class="ulist"> <ul> <li> <p>the argument given with the <code>--template</code> option;</p> </li> <li> <p>the contents of the <code>$GIT_TEMPLATE_DIR</code> environment variable;</p> </li> <li> <p>the <code>init.templateDir</code> configuration variable; or</p> </li> <li> <p>the default template directory: <code>/usr/share/git-core/templates</code>.</p> </li> </ul> </div> <p>The default template directory includes some directory structure, suggested "exclude patterns" (see <a href="gitignore">gitignore[5]</a>), and sample hook files.</p> <p>The sample hooks are all disabled by default. To enable one of the sample hooks rename it by removing its <code>.sample</code> suffix.</p> <p>See <a href="githooks">githooks[5]</a> for more general info on hook execution.</p> </div> <h2 id="_examples">Examples</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-init.txt-StartanewGitrepositoryforanexistingcodebase"> Start a new Git repository for an existing code base </dt> <dd> <div class="listingblock"> <div class="content"> <pre data-language="shell-session">$ cd /path/to/my/codebase
$ git init (1)
$ git add . (2)
$ git commit (3)</pre> </div> </div> <div class="colist arabic"> <ol> <li> <p>Create a /path/to/my/codebase/.git directory.</p> </li> <li> <p>Add all existing files to the index.</p> </li> <li> <p>Record the pristine state as the first commit in the history.</p> </li> </ol> </div> </dd> </dl> </div> </div> <h2 id="_configuration">Configuration</h2> <div class="sectionbody"> <p>Everything below this line in this section is selectively included from the <a href="git-config">git-config[1]</a> documentation. The content is the same as what’s found there:</p> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-init.txt-inittemplateDir"> init.templateDir </dt> <dd> <p>Specify the directory from which templates will be copied. (See the "TEMPLATE DIRECTORY" section of <a href="git-init">git-init[1]</a>.)</p> </dd> <dt class="hdlist1" id="Documentation/git-init.txt-initdefaultBranch"> init.defaultBranch </dt> <dd> <p>Allows overriding the default branch name e.g. when initializing a new repository.</p> </dd> </dl> </div> </div><div class="_attribution">
<p class="_attribution-p">
© 2012–2024 Scott Chacon and others<br>Licensed under the MIT License.<br>
<a href="https://git-scm.com/docs/git-init" class="_attribution-link">https://git-scm.com/docs/git-init</a>
</p>
</div>
|