📚 Gitチートシート
開発者のための完全なGitコマンドリファレンス。commit、push、pull、branch、mergeなどのGitコマンドを検索してコピーできます。
💡 使用ヒント: コマンド横の「コピー」ボタンをクリックすると素早くコピーできます。カテゴリータイトルをクリックすると内容を展開/折りたたみできます。
⚙️ 設定
▼
git config --global user.name "[name]"
グローバルユーザー名を設定
git config --global user.email "[email]"
グローバルメールを設定
git config --global core.editor "[editor]"
デフォルトエディタを設定
git config --global color.ui true
カラー出力を有効化
git config --global alias.co checkout
コマンドエイリアスを設定 (checkout → co)
🚀 リポジトリ作成
▼
git init
新しいGitリポジトリを初期化
git clone [url]
リモートリポジトリをローカルにクローン
git clone -b [branch] [url]
指定ブランチをクローン
💾 基本コミット
▼
git status
作業ディレクトリの状態を表示
git add [file]
ファイルをステージングエリアに追加
git add .
全ての変更ファイルを追加
git commit -m "[message]"
ステージした内容をコミット
git commit -am "[message]"
追跡済みの変更を全てコミット
git commit --amend
最後のコミットを修正
git commit --amend --no-edit
メッセージを変更せずにコミットを修正
🌿 ブランチ管理
▼
git branch
ローカルブランチリストを表示
git branch -a
全てのブランチを表示(リモート含む)
git branch [branch-name]
新しいブランチを作成
git checkout [branch-name]
指定ブランチに切り替え
git checkout -b [branch-name]
新しいブランチを作成して切り替え
git branch -d [branch-name]
マージ済みブランチを削除
git branch -D [branch-name]
強制的にブランチを削除
git branch -m [old-name] [new-name]
ブランチ名を変更
☁️ リモート操作
▼
git remote -v
リモートリポジトリ情報を表示
git remote add origin [url]
リモートリポジトリを追加
git pull [remote] [branch]
リモートの更新をプル
git push [remote] [branch]
ローカルブランチをプッシュ
git push -f [remote] [branch]
強制プッシュ(リモートを上書き)
git fetch [remote]
リモートの更新を取得(マージなし)
git remote remove [remote]
リモートリポジトリを削除
🔀 マージとリベース
▼
git merge [branch]
指定ブランチを現在のブランチにマージ
git merge --no-ff [branch]
マージコミットを作成してマージ
git rebase [branch]
指定ブランチにリベース
git rebase --continue
リベース操作を継続
git rebase --abort
リベース操作を中止
↩️ 取消とロールバック
▼
git reset HEAD~1
最後のコミットを取消(変更を保持)
git reset HEAD~[N]
最後のN個のコミットを取消
git reset --hard HEAD~1
コミットを取消して変更を破棄
git reset --hard [commit-hash]
指定コミットにロールバック
git checkout -- [file]
ローカルファイルの変更を破棄
git revert [commit-hash]
指定コミットを取消す新規コミットを作成
git clean -fd
未追跡のファイルとディレクトリを削除
🔍 履歴を表示
▼
git log
コミット履歴を表示
git log --oneline
簡潔な1行履歴
git log --graph --oneline
グラフィカルなブランチ履歴
git log --stat
コミット統計を表示
git diff
作業ディレクトリの差分を表示
git diff --staged
ステージした差分を表示
git show [commit-hash]
指定コミットの詳細を表示
🏷️ タグ管理
▼
git tag
タグリストを表示
git tag [tag-name]
軽量タグを作成
git tag -a [tag-name] -m "[message]"
注釈付きタグを作成
git push [remote] [tag-name]
タグをリモートにプッシュ
git push [remote] --tags
全てのタグをプッシュ
git tag -d [tag-name]
ローカルタグを削除
📦 スタッシュとステージ
▼
git stash
現在の変更をスタッシュ
git stash save "[message]"
メッセージ付きでスタッシュ
git stash list
スタッシュリストを表示
git stash apply
スタッシュを復元(削除なし)
git stash pop
スタッシュを復元して削除
git stash drop
最新のスタッシュを削除
git stash clear
全てのスタッシュをクリア
🧩 サブモジュール
▼
git submodule add [url] [path]
サブモジュールを追加
git submodule init
サブモジュールを初期化
git submodule update
サブモジュールを更新
⚡ 高度なヒント
▼
git cherry-pick [commit-hash]
指定コミットを選択して適用
git bisect start [bad] [good]
問題を特定するための二分探索
git blame [file]
ファイルの修正履歴を表示
git reflog
全ての操作記録を表示
git clean -xdf
作業ディレクトリを徹底的にクリーン(注意して使用)
git gc --aggressive
リポジトリを圧縮して最適化