git init

git

書き方

git init [-b <branch>] [<directory>]

フォルダーを新しいgitリポジトリにします。initだけではファイルは追跡されず、addとcommitが別に必要です。

よく使うオプション

オプション意味
-b <name>name the first branch, e.g. main
--barerepository with no working tree, for a server
--template=<dir>copy hooks and files from a template directory
--separate-git-dir=<dir>keep the .git directory somewhere else
-qprint nothing but errors

git init

turns the current folder into a repository by creating .git

git init -b main my-app

creates my-app/ with its first branch named main

git init --separate-git-dir=~/gitdirs/app.git

keeps the .git directory elsewhere and leaves a pointer file

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git init は何をしますか。

フォルダーを新しいgitリポジトリにします。initだけではファイルは追跡されず、addとcommitが別に必要です。

Q. どう打ちますか。

git init [-b <branch>] [<directory>] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは5個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-init