[ad_1]
Git/GitHub環境構築ガイド【2025年最新版・Windows/Mac/Ubuntu対応】¶
現代のソフトウェア開発において、Git/GitHubは必須のツールです。バージョン管理システムのGitと、クラウドベースのリポジトリホスティングサービスであるGitHubを組み合わせることで、コードの変更履歴管理、チーム開発での協業、オープンソースプロジェクトへの貢献が可能になります。本ガイドでは、2025年最新版のGit/GitHub環境構築を、Windows 11、macOS、Ubuntuの各OSに対応して詳しく解説します。
前提条件¶
システム要件¶
Windows 11:
– RAM: 4GB以上(8GB推奨)
– ストレージ: 1GB以上の空き容量
– インターネット接続環境
macOS:
– macOS 10.9以降
– Xcode Command Line Tools(後述で自動インストール)
– RAM: 4GB以上
– ストレージ: 1GB以上の空き容量
Ubuntu:
– Ubuntu 18.04 LTS以降
– RAM: 2GB以上(4GB推奨)
– ストレージ: 1GB以上の空き容量
– sudo権限
事前準備¶
- GitHubアカウントの作成準備(メールアドレス)
- 任意のテキストエディタ(VS Code推奨)
- ターミナル/コマンドプロンプトの基本操作知識
Gitのインストール¶
💡 開発環境をもっと快適に!
Visual Studio Code や WebStorm などの高機能エディタで開発効率アップ!
Windows 11での手順¶
- 公式サイトからダウンロード
- Git for Windowsにアクセス
- 「Download for Windows」をクリック
-
最新版(Git 2.49.0)のインストーラーをダウンロード
-
インストーラーの実行
- ダウンロードしたexeファイルを右クリック→「管理者として実行」
- ライセンス画面で「Next」をクリック
- インストール先は通常デフォルトのまま「Next」
-
コンポーネント選択では以下を確認:
- ✓ Windows Explorer integration
- ✓ Git Bash Here
- ✓ Git GUI Here
- ✓ Associate .git* configuration files with the default text editor
-
重要な設定項目
- デフォルトエディタ: 「Use Visual Studio Code as Git’s default editor」を選択(VS Code使用の場合)
- デフォルトブランチ名: 「Override the default branch name for new repositories」を選択し、「main」と入力
- PATH環境変数: 「Git from the command line and also from 3rd-party software」を選択
- HTTPS transport backend: 「Use the native Windows Secure Channel library」を選択
- 改行コード変換: 「Checkout Windows-style, commit Unix-style line endings」を選択
macOSでの手順¶
- Homebrewを使った方法(推奨)
# Homebrewがインストールされていない場合
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Gitのインストール
brew install git
- Xcode Command Line Toolsを使った方法
# コマンドラインツールのインストール
xcode-select --install
# インストール確認
git --version
Ubuntuでの手順¶
# パッケージリストの更新
sudo apt update
# Gitのインストール
sudo apt install git
# 最新版を使いたい場合(PPAを使用)
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
インストール確認¶
💡 開発環境をもっと快適に!
Visual Studio Code や WebStorm などの高機能エディタで開発効率アップ!
全てのOSで以下のコマンドでインストールを確認します:
git --version
出力例:
git version 2.49.0
Git初期設定¶
ユーザー情報の設定¶
# グローバル設定(全リポジトリに適用)
git config --global user.name "あなたの名前"
git config --global user.email "your.email@example.com"
# デフォルトブランチ名をmainに設定
git config --global init.defaultBranch main
# プルの動作を設定(Git 2.27.0以降必須)
git config --global pull.rebase false
追加の便利な設定¶
# 自動的に不要なリモートブランチ参照を削除
git config --global fetch.prune true
# すべての未トラックファイルを表示
git config --global status.showUntrackedFiles all
# クロスプラットフォーム対応の改行コード処理
git config --global core.autocrlf input # Mac/Linux
git config --global core.autocrlf true # Windows
# カラー表示を有効化
git config --global color.ui auto
# エイリアスの設定(便利なショートカット)
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
設定確認¶
# 全ての設定を確認
git config --global --list
# 特定の設定を確認
git config --global user.name
git config --global user.email
GitHubアカウントの作成¶
- GitHubサイトにアクセス
- GitHub.comにアクセス
-
「Sign up for GitHub」をクリック
-
アカウント情報入力
- ユーザー名: 英数字とハイフンのみ使用可能
- メールアドレス: 確認メールが送信されます
-
パスワード: 8文字以上、数字と小文字を含む
-
アカウント認証
- パズル認証を完了
- 送信された確認メールのリンクをクリック
SSH鍵の設定¶
SSH鍵の生成¶
# SSH鍵の生成
ssh-keygen -t ed25519 -C "your.email@example.com"
# 古いシステムでed25519が使えない場合
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
プロンプトが表示されたら:
1. ファイル保存場所: Enterキーでデフォルト(~/.ssh/id_ed25519)
2. パスフレーズ: セキュリティ強化のため設定推奨
SSH-Agentの設定¶
macOS/Linux:
# SSH-Agentの開始
eval "$(ssh-agent -s)"
# SSH鍵をagentに追加
ssh-add ~/.ssh/id_ed25519
Windows(Git Bash):
# SSH-Agentの開始
eval $(ssh-agent -s)
# SSH鍵をagentに追加
ssh-add ~/.ssh/id_ed25519
GitHubへのSSH鍵登録¶
- 公開鍵の表示
# 公開鍵の内容を表示
cat ~/.ssh/id_ed25519.pub
- GitHubでの設定
- GitHubにログイン
- 右上のプロフィール画像 → 「Settings」
- 左メニューから「SSH and GPG keys」
- 「New SSH key」をクリック
- Title: 識別しやすい名前(例:「My Laptop」)
- Key: コピーした公開鍵を貼り付け
- 「Add SSH key」をクリック
接続テスト¶
# GitHub接続テスト
ssh -T git@github.com
[ad_2]
成功時の出力例:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
動作確認¶
初回リポジトリ作成とプッシュ¶
- GitHubでリポジトリ作成
- GitHub上で「New repository」をクリック
- Repository name: 「test-repo」
-
「Create repository」をクリック
-
ローカルでリポジトリ初期化
# 作業ディレクトリ作成
mkdir test-repo
cd test-repo
# Gitリポジトリ初期化
git init
# READMEファイル作成
echo "# Test Repository" > README.md
# ファイルをステージング
git add README.md
# 初回コミット
git commit -m "Initial commit"
# リモートリポジトリ追加
git remote add origin git@github.com:あなたのユーザー名/test-repo.git
# mainブランチにプッシュ
git push -u origin main
動作確認コマンド¶
# リポジトリ状態確認
git status
# コミット履歴確認
git log --oneline
# リモートリポジトリ確認
git remote -v
# ブランチ確認
git branch -a
よくあるトラブルと対処法¶
1. 認証エラー(403 Forbidden)¶
症状:
remote: Support for password authentication was removed on August 13, 2021.
対処法:
– パスワードではなくPersonal Access Token(PAT)を使用
– SSH鍵認証に切り替える(推奨)
2. SSH接続エラー¶
症状:
ssh: connect to host github.com port 22: Connection timed out
対処法:
# HTTPS over SSH(ポート443使用)
echo "Host github.com
Hostname ssh.github.com
Port 443
User git" >> ~/.ssh/config
3. 改行コードの問題¶
症状: Windows/Unix間でファイルが変更されて見える
対処法:
# Windows
git config --global core.autocrlf true
# Mac/Linux
git config --global core.autocrlf input
4. ブランチ名の不一致¶
症状: master
とmain
ブランチの混在
対処法:
# 既存リポジトリのブランチ名変更
git branch -m master main
git push -u origin main
git push origin --delete master
5. コミットメッセージの修正¶
症状: 直前のコミットメッセージを修正したい
対処法:
# 直前のコミットメッセージ修正
git commit --amend -m "修正されたコミットメッセージ"
6. Node.jsバージョンエラー(CLI使用時)¶
症状: Zenn CLIやQiita CLIでバージョンエラー
対処法:
# Node.jsバージョン確認
node --version
# 必要に応じてNode.jsアップデート
# Zenn CLI: Node.js 14以上
# Qiita CLI: Node.js 18.18.0以上
便利な追加設定¶
エディタとの連携¶
VS Codeとの連携:
# VS CodeをGitのデフォルトエディタに設定
git config --global core.editor "code --wait"
# マージツールとしてVS Codeを使用
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
Gitignoreテンプレート¶
プロジェクトルートに.gitignore
ファイルを作成:
# 言語別テンプレート取得
curl https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore > .gitignore
curl https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore > .gitignore
コミットテンプレート¶
# コミットテンプレート作成
echo "# タイトル(50文字以内)
# 本文(72文字で改行)
# - 何を変更したか
# - なぜ変更したか
# - どのような影響があるか" > ~/.gitmessage
# テンプレート設定
git config --global commit.template ~/.gitmessage
ブランチ自動補完¶
Bash:
# .bashrcに追加
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
Zsh:
# .zshrcに追加
autoload -Uz compinit && compinit
GitHub CLI(gh)のインストール¶
Windows:
winget install --id GitHub.cli
macOS:
brew install gh
Ubuntu:
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
GitHub CLI認証:
# GitHub CLIでログイン
gh auth login
# リポジトリ作成例
gh repo create my-project --public --clone
まとめ¶
本ガイドでは、2025年最新のGit/GitHub環境構築について、Windows 11、macOS、Ubuntuの各OSに対応した手順を詳しく解説しました。重要なポイントをまとめると:
- 最新版の使用: Git 2.49.0の最新機能を活用
- セキュアな認証: SSH鍵認証によるセキュリティ強化
- 適切な初期設定: 現代的な開発ワークフローに対応した設定
- トラブル対応: よくある問題の予防と解決方法
Git/GitHubは現代のソフトウェア開発に欠かせないツールです。この環境構築により、個人開発からチーム開発、オープンソース貢献まで、様々な開発活動の基盤が整います。設定完了後は、実際にコードを書きながらGitの基本操作(add、commit、push、pull、merge)を習得し、効率的な開発ワークフローを身につけていきましょう。
継続的な学習として、GitHub Actions、GitHub Copilot、Git Flow、GitHub Flow などの発展的なトピックにも挑戦することで、より生産性の高い開発環境を構築できます。
おすすめ関連商品¶
開発環境構築におすすめのツール・書籍¶
- Docker実践ガイド
- 開発環境構築に必須のスキル
-
コンテナ技術を基礎から学習
- エディタの活用テクニック
-
拡張機能の効果的な使い方
- バージョン管理の基礎から応用
- チーム開発での活用方法
開発効率を上げるツール・サービス¶
- GitHub Copilot – AI支援コーディング
- AWS Free Tier – クラウド環境で実践
- O’Reilly Learning – 技術書読み放題
[ad_3]
コメント