基本的なGitコマンド解説

基本的なGitコマンド

git init - リポジトリの初期化

新しいGitリポジトリを作成します。

オプション 説明
--bare 作業ディレクトリなしのベアリポジトリを作成
--template=<テンプレートディレクトリ> 指定したテンプレートディレクトリからテンプレートを使用

例:

git init - カレントディレクトリに新しいGitリポジトリを作成
git init my_project - 指定したディレクトリに新しいGitリポジトリを作成
git init --bare remote_repo.git - ベアリポジトリを作成(サーバー用)

git clone - リポジトリのクローン

既存のリポジトリをローカルにコピーします。

オプション 説明
--branch, -b <ブランチ名> 指定したブランチをチェックアウト
--depth <深さ> 指定した深さの浅いクローンを作成
--recursive サブモジュールも含めて再帰的にクローン

例:

git clone https://github.com/username/repository.git - リモートリポジトリをクローン
git clone https://github.com/username/repository.git my_folder - 指定したフォルダにクローン
git clone --branch develop https://github.com/username/repository.git - 特定のブランチをクローン
git clone --depth 1 https://github.com/username/repository.git - 最新のコミットのみをクローン(履歴なし)