git-init.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. git-init(1)
  2. ===========
  3. NAME
  4. ----
  5. git-init - Create an empty Git repository or reinitialize an existing one
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'git init' [-q | --quiet] [--bare] [--template=<template_directory>]
  10. [--separate-git-dir <git dir>] [--object-format=<format>]
  11. [-b <branch-name> | --initial-branch=<branch-name>]
  12. [--shared[=<permissions>]] [directory]
  13. DESCRIPTION
  14. -----------
  15. This command creates an empty Git repository - basically a `.git`
  16. directory with subdirectories for `objects`, `refs/heads`,
  17. `refs/tags`, and template files. An initial `HEAD` file that
  18. references the HEAD of the master branch is also created.
  19. If the `$GIT_DIR` environment variable is set then it specifies a path
  20. to use instead of `./.git` for the base of the repository.
  21. If the object storage directory is specified via the
  22. `$GIT_OBJECT_DIRECTORY` environment variable then the sha1 directories
  23. are created underneath - otherwise the default `$GIT_DIR/objects`
  24. directory is used.
  25. Running 'git init' in an existing repository is safe. It will not
  26. overwrite things that are already there. The primary reason for
  27. rerunning 'git init' is to pick up newly added templates (or to move
  28. the repository to another place if --separate-git-dir is given).
  29. OPTIONS
  30. -------
  31. -q::
  32. --quiet::
  33. Only print error and warning messages; all other output will be suppressed.
  34. --bare::
  35. Create a bare repository. If `GIT_DIR` environment is not set, it is set to the
  36. current working directory.
  37. --object-format=<format>::
  38. Specify the given object format (hash algorithm) for the repository. The valid
  39. values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default.
  40. +
  41. include::object-format-disclaimer.txt[]
  42. --template=<template_directory>::
  43. Specify the directory from which templates will be used. (See the "TEMPLATE
  44. DIRECTORY" section below.)
  45. --separate-git-dir=<git dir>::
  46. Instead of initializing the repository as a directory to either `$GIT_DIR` or
  47. `./.git/`, create a text file there containing the path to the actual
  48. repository. This file acts as filesystem-agnostic Git symbolic link to the
  49. repository.
  50. +
  51. If this is reinitialization, the repository will be moved to the specified path.
  52. -b <branch-name::
  53. --initial-branch=<branch-name>::
  54. Use the specified name for the initial branch in the newly created repository.
  55. If not specified, fall back to the default name: `master`.
  56. --shared[=(false|true|umask|group|all|world|everybody|0xxx)]::
  57. Specify that the Git repository is to be shared amongst several users. This
  58. allows users belonging to the same group to push into that
  59. repository. When specified, the config variable "core.sharedRepository" is
  60. set so that files and directories under `$GIT_DIR` are created with the
  61. requested permissions. When not specified, Git will use permissions reported
  62. by umask(2).
  63. +
  64. The option can have the following values, defaulting to 'group' if no value
  65. is given:
  66. +
  67. --
  68. 'umask' (or 'false')::
  69. Use permissions reported by umask(2). The default, when `--shared` is not
  70. specified.
  71. 'group' (or 'true')::
  72. Make the repository group-writable, (and g+sx, since the git group may be not
  73. the primary group of all users). This is used to loosen the permissions of an
  74. otherwise safe umask(2) value. Note that the umask still applies to the other
  75. permission bits (e.g. if umask is '0022', using 'group' will not remove read
  76. privileges from other (non-group) users). See '0xxx' for how to exactly specify
  77. the repository permissions.
  78. 'all' (or 'world' or 'everybody')::
  79. Same as 'group', but make the repository readable by all users.
  80. '0xxx'::
  81. '0xxx' is an octal number and each file will have mode '0xxx'. '0xxx' will
  82. override users' umask(2) value (and not only loosen permissions as 'group' and
  83. 'all' does). '0640' will create a repository which is group-readable, but not
  84. group-writable or accessible to others. '0660' will create a repo that is
  85. readable and writable to the current user and group, but inaccessible to others.
  86. --
  87. By default, the configuration flag `receive.denyNonFastForwards` is enabled
  88. in shared repositories, so that you cannot force a non fast-forwarding push
  89. into it.
  90. If you provide a 'directory', the command is run inside it. If this directory
  91. does not exist, it will be created.
  92. TEMPLATE DIRECTORY
  93. ------------------
  94. Files and directories in the template directory whose name do not start with a
  95. dot will be copied to the `$GIT_DIR` after it is created.
  96. The template directory will be one of the following (in order):
  97. - the argument given with the `--template` option;
  98. - the contents of the `$GIT_TEMPLATE_DIR` environment variable;
  99. - the `init.templateDir` configuration variable; or
  100. - the default template directory: `/usr/share/git-core/templates`.
  101. The default template directory includes some directory structure, suggested
  102. "exclude patterns" (see linkgit:gitignore[5]), and sample hook files.
  103. The sample hooks are all disabled by default. To enable one of the
  104. sample hooks rename it by removing its `.sample` suffix.
  105. See linkgit:githooks[5] for more general info on hook execution.
  106. EXAMPLES
  107. --------
  108. Start a new Git repository for an existing code base::
  109. +
  110. ----------------
  111. $ cd /path/to/my/codebase
  112. $ git init <1>
  113. $ git add . <2>
  114. $ git commit <3>
  115. ----------------
  116. +
  117. <1> Create a /path/to/my/codebase/.git directory.
  118. <2> Add all existing files to the index.
  119. <3> Record the pristine state as the first commit in the history.
  120. GIT
  121. ---
  122. Part of the linkgit:git[1] suite