git init
git
書き方
git init [-b <branch>] [<directory>]フォルダーを新しいgitリポジトリにします。initだけではファイルは追跡されず、addとcommitが別に必要です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -b <name> | name the first branch, e.g. main |
| --bare | repository 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 |
| -q | print nothing but errors |
例
git initturns the current folder into a repository by creating .git
git init -b main my-appcreates my-app/ with its first branch named main
git init --separate-git-dir=~/gitdirs/app.gitkeeps 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