バージョン管理ツールgitでよく使うコマンドをまとめておく。
clone関連
- リモートリポジトリをローカルにclone
git clone https://github.com/***/***.git
- ローカルリポジトリ名を指定してリモートリポジトリをclone
git clone https://github.com/***/***.git フォルダ名
commit関連
- 変更したファイル・フォルダをcommit対象として追加
git add file1 folder1
- ローカルのファイル・フォルダの変更状態を確認する
git status
- addしたファイル・フォルダをcommitする
git commit -m "コミットログ"
- commitしたログを確認する
git log
- commitした内容をリモートリポジトリへpushする
git push origin ブランチ名
今いるブランチのリモートリポジトリにpushしたい場合はブランチ名をHEADにしてもできる
- 現在のフォルダ以下の全ての変更をコミットする
git commit .
- ローカルの変更を元に戻す
git restore ファイルパス
サブモジュール関連
- サブモジュールのソースを含めてリモートリポジトリをclone
git clone --recursive https://github.com/***/***.git
- --recursiveを忘れてcloneしてしまったが、やっぱりサブモジュールのソースをアップデートしたい
git submodule update --init
- 特定のサブモジュールをアップデートする
git submodule update --remote サブモジュールのリポジトリパス
- 全てのサブモジュールを強制的にアップデートする
git submodule foreach git pull origin master
diff関連
- ローカルリポジトリの全ての変更を確認する
git diff
- ローカルリポジトリの変更があるファイル名だけを確認する
git diff --name-only
- コミット同士のdiffを確認する
git diff 変更前のSHA..変更後のSHA
ブランチ関連
- ブランチ一覧を表示する
git branch
- ローカルリポジトリを他のブランチに切り替える
git switch ブランチ名
- リモートのブランチリポジトリをcloneする
git clone -b ブランチ名 https://github.com/***/***.git