付録C コマンドチートシート

概要

頻出コマンドの 1 ページ要約です。詳しい説明は本編の各章を参照してください。

Git 基本コマンド

コマンド

用途

git --version

バージョン確認

3

git config --global user.name "名前"

ユーザー名設定

3

git init

リポジトリ作成

4

git status

状態確認

4

git add <file>

ステージング

5

git add .

全変更をステージ

5

git commit -m "msg"

コミット

5

git log --oneline

履歴 (簡易)

6

git log --graph --oneline --all

履歴 (グラフ)

6

git diff

作業ツリー vs index

6

git diff --staged

index vs HEAD

6

git show <commit>

1 コミットの詳細

6

git restore <file>

編集破棄

6

git restore --staged <file>

unstage

6

git revert <commit>

打ち消しコミット

6

リモート操作

コマンド

用途

git remote -v

リモート一覧

8

git push -u origin main

初回 push

8

git push

通常 push

8

git pull

fetch + merge

10

git fetch

取り込みのみ

10

git clone <url>

クローン

10

.gitignore 例

# secrets
.env
.env.*

# Windows
Thumbs.db
desktop.ini

# Python
__pycache__/
*.pyc
.venv/

# Editors
.vscode/
*.swp

# Logs
*.log

GitHub CLI (gh)

コマンド

用途

gh auth login

GitHub 認証

3

gh auth status

認証確認

3

gh repo create --source=. --private --remote=origin

リモート作成

8

gh repo clone <user>/<repo>

クローン

10

gh browse

ブラウザで開く

8

gh issue create -t "title" -b "body"

Issue 作成

9

gh issue list

Issue 一覧

9

gh issue view <N>

Issue 詳細

9

gh issue close <N>

手動クローズ

9

gh issue edit <N> --add-label "bug"

ラベル追加

9

コミットメッセージの自動クローズ

fix login flow

Closes #1
Fixes #2
Resolves #3

デフォルトブランチへの push でこれら Issue が自動クローズされます。

トラブルシューティング (付録 B 参照)

  • 改行コード警告 → 無視可

  • not a git repositorycd で正しい場所へ

  • 認証失敗 → gh auth login 再実行

  • push reject → git pull してから git push