Gitの使用は基本ですが、度々忘れることがあるので備忘用に記載します。
初期設定系
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main
ローカルの基本操作
git init # 既存フォルダをGit管理下に置く
git clone <URL> # リモートリポジトリをローカルにコピー
変更状況の確認
git status # 変更されたファイル一覧
git diff # 実際の変更内容(差分)
ステージング
git add <ファイル名> # ステージに追加
git add . # 全部追加
コミット
git commit -m "説明文" # スナップショットを記録
リモートの追加&確認
git remote add origin <URL> # リモート設定(初回のみ)
git remote -v # 現在のリモート確認
プッシュ・プル
git push origin main # ローカル → リモートに反映
git pull origin main # リモート → ローカルに反映
ブランチ作成・切り替え
git branch <ブランチ名> # 作成
git switch <ブランチ名> # 切り替え
ブランチ削除
git branch -d <ブランチ名> # マージ済みブランチを削除
マージ
git merge <ブランチ名> # 今いるブランチに指定ブランチを統合
競合発生時
git add <修正済ファイル>
git commit # 解決後にコミット
コミット前の変更を取り消し
git restore <ファイル名> # 編集をなかったことに
add した変更を取り消し
git reset HEAD <ファイル名>
直前のコミットをやり直し
git commit --amend
よく使う便利コマンド
git log --oneline --graph --all # 見やすいログ
git stash # 途中作業を一時退避
git stash pop # 一時退避の復元
よくあるワークフロー
①main ブランチを pull
②作業ブランチを切る git checkout -b feature/hogehoge
③作業して commit
③git push origin feature/hogehoge
④PR(プルリク)を出す
⑤レビュー&マージ
⑥main を最新化して次のタスクへ