Git 逆引きチートシート
初期設定
名前とメールを設定
git config --global user.name "名前"
git config --global user.email "email@example.com"
設定確認
git config --list
リポジトリ操作
新規作成
git init
クローン
git clone https://github.com/user/repo.git
状態確認
git status
変更履歴
git log --oneline -10
コミット
全ファイルをステージング
git add -A
特定ファイルのみ
git add file1.md file2.py
コミット
git commit -m "メッセージ"
ステージング + コミット(一括)
git commit -am "メッセージ"
追跡済みファイル(既にgit管理下)のみ -am で一括可能。新規ファイルは git add が必要
リモート操作
プッシュ
git push
初回プッシュ(追跡設定)
git push -u origin main
プル
git pull
リモート一覧
git remote -v
リモート変更(HTTPS→SSH)
git remote set-url origin git@github.com:user/repo.git
ブランチ
一覧
git branch -a
作成 + 切り替え
git checkout -b feature/new-feature
切り替え
git checkout main
削除
git branch -d feature/new-feature
取り消し
ステージング取消(ファイルはそのまま)
git restore --staged file.md
変更を破棄(元に戻す)
git restore file.md
直前のコミットを取り消し(変更は残る)
git reset HEAD~1
git reset --hard は変更も消えるので注意!
確認・調査
差分確認
git diff
ステージング済み差分
git diff --staged
誰がいつ変更したか
git blame file.md
特定コミットの詳細
git show abc1234
← ガイド一覧に戻る