Git & GitHub セットアップ
chroはバージョン管理にGitを、コラボレーションにGitHubを使用します。このガイドでは、両プラットフォームでのインストールとSSH鍵のセットアップについて説明します。
既存のインストール確認
Section titled “既存のインストール確認”まず、Gitがすでにインストールされているか確認します:
git --versionGitがインストールされていれば、バージョン番号が表示されます。そうでない場合は、以下のインストール手順に従ってください。
方法1: Xcode Command Line Tools(推奨)
Section titled “方法1: Xcode Command Line Tools(推奨)”macOSでGitを入手する最も簡単な方法:
xcode-select --installダイアログが表示されます。「インストール」をクリックして完了を待ちます。
方法2: Homebrew
Section titled “方法2: Homebrew”Homebrewがインストールされている場合:
brew install gitインストールの確認
Section titled “インストールの確認”git --version # git version 2.x.x と表示されるはずWindows
Section titled “Windows”方法1: winget(推奨)
Section titled “方法1: winget(推奨)”Windowsパッケージマネージャーを使用:
winget install Git.Git注意: インストール後、ターミナルを再起動してください。
方法2: Git for Windows インストーラー
Section titled “方法2: Git for Windows インストーラー”- git-scm.comからダウンロード
- インストーラーを実行
- デフォルト設定を使用(初心者には推奨)
- 「Git from the command line and also from 3rd-party software」が選択されていることを確認
インストールの確認
Section titled “インストールの確認”新しいターミナル/PowerShellウィンドウを開きます:
git --versionGitの初期設定
Section titled “Gitの初期設定”ID(コミットに必要)を設定します:
git config --global user.name "あなたの名前"デフォルトブランチ名をmainに設定:
git config --global init.defaultBranch main設定を確認:
git config --listGitHubアカウントのセットアップ
Section titled “GitHubアカウントのセットアップ”GitHubアカウントをお持ちでない場合:
- github.comにアクセス
- 「Sign up」をクリック
- 登録プロセスに従う
- メールアドレスを確認
SSH鍵のセットアップ(推奨)
Section titled “SSH鍵のセットアップ(推奨)”SSH鍵は、GitHubとのセキュアでパスワード不要の認証を提供します。
SSH鍵の生成
Section titled “SSH鍵の生成”macOS / Linux / Windows(Git BashまたはWSL):
プロンプトが表示されたら:
- Enterキーを押してデフォルトのファイル場所を受け入れる
- パスフレーズを入力(推奨)またはEnterキーでパスフレーズなし
Windows(PowerShell):
SSHエージェントの起動
Section titled “SSHエージェントの起動”macOS:
eval "$(ssh-agent -s)"~/.ssh/configに追加(存在しない場合は作成):
Host github.com AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519鍵を追加:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519Windows(PowerShell - 管理者として実行):
# ssh-agentサービスを開始Get-Service -Name ssh-agent | Set-Service -StartupType AutomaticStart-Service ssh-agent
# 鍵を追加ssh-add $env:USERPROFILE\.ssh\id_ed25519Linux / WSL:
eval "$(ssh-agent -s)"ssh-add ~/.ssh/id_ed25519SSH鍵をGitHubに追加
Section titled “SSH鍵をGitHubに追加”1. 公開鍵をコピー:
macOS:
pbcopy < ~/.ssh/id_ed25519.pubWindows(PowerShell):
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-ClipboardLinux:
cat ~/.ssh/id_ed25519.pub# 出力を手動でコピー2. GitHubに追加:
- GitHub設定 > SSH Keysにアクセス
- 「New SSH key」をクリック
- わかりやすいタイトルを入力(例:「MacBook Pro 2024」)
- 「Key」フィールドに鍵を貼り付け
- 「Add SSH key」をクリック
以下のように表示されるはずです:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.代替手段: 個人アクセストークンを使用したHTTPS
Section titled “代替手段: 個人アクセストークンを使用したHTTPS”SSHよりHTTPSを好む場合:
個人アクセストークンの作成
Section titled “個人アクセストークンの作成”- GitHub設定 > Developer Settings > Personal Access Tokensにアクセス
- 「Generate new token (classic)」をクリック
- わかりやすい名前を入力
- スコープを選択:
repo(プライベートリポジトリの完全な制御) - 「Generate token」をクリック
- トークンをすぐにコピー(再度表示されません)
Git認証情報ストレージの設定
Section titled “Git認証情報ストレージの設定”macOS:
git config --global credential.helper osxkeychainWindows:
git config --global credential.helper wincred初めてpush/pullするとき、GitHubユーザー名を入力し、パスワードとしてトークンを使用します。
GitHub接続の確認
Section titled “GitHub接続の確認”リポジトリをクローンしてテスト:
# SSH(推奨)
# またはHTTPSgit clone https://github.com/octocat/Hello-World.git成功すれば、GitでGitHubを使用する準備ができています!
トラブルシューティング
Section titled “トラブルシューティング””Permission denied (publickey)”
Section titled “”Permission denied (publickey)””- SSH鍵がエージェントに追加されていることを確認:
ssh-add -l - 鍵がGitHubに追加されていることを確認:github.com/settings/keys
- 正しい鍵を使用していることを確認:
ssh -vT [email protected]
”Could not open a connection to your authentication agent”
Section titled “”Could not open a connection to your authentication agent””SSHエージェントを起動:
eval "$(ssh-agent -s)"Gitがpushのたびにパスワードを要求(HTTPS)
Section titled “Gitがpushのたびにパスワードを要求(HTTPS)”認証情報ストレージを設定:
# macOSgit config --global credential.helper osxkeychain
# Windowsgit config --global credential.helper wincred
# Linuxgit config --global credential.helper store改行コードの問題(Windows)
Section titled “改行コードの問題(Windows)”改行を処理するようにGitを設定:
git config --global core.autocrlf true次のステップ
Section titled “次のステップ”GitとGitHubの設定が完了したら、次に進んでください:
- AIコーディングツールのセットアップ - Claude CodeまたはOpenAI Codexをインストール
- chroのインストール - chroをインストール