この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:6
ページ更新者:T
更新日時:2026-06-11 07:10:02

タイトル: バージョンの確認
SEOタイトル: git バージョン確認方法完全ガイド(git --version / 最新化 / 互換性)

この記事の要点
  • git --version が最も基本。git version も同じ
  • 表示は 3 桁 (例 git version 2.45.1)、Mac は git version 2.39.5 (Apple Git-154) のような注釈付き
  • Mac 標準は Xcode CLT 同梱で古いbrew install git で最新化
  • Windows は Git for Windows、WSL は別系統 (apt の git)
  • git switch / git restore2.23+ 必要、git sparse-checkout2.25+

git バージョン確認の基本

# 推奨
git --version
# git version 2.45.1

# 同じ意味 (短い)
git version
# git version 2.45.1

# 詳細 (ビルド情報込み、Git 2.20+)
git version --build-options
# git version 2.45.1
# cpu: arm64
# no commit associated with this build
# sizeof-long: 8
# sizeof-size_t: 8
# shell-path: /bin/sh

OS 別の確認方法

OSコマンド典型表示
Linux (apt)git --versiongit version 2.39.2
macOS (Xcode CLT)git --versiongit version 2.39.5 (Apple Git-154)
macOS (Homebrew)/usr/local/bin/git --version or brew info gitgit version 2.45.1
Windows (Git for Windows)git --versiongit version 2.45.1.windows.1
WSL Ubuntugit --versiongit version 2.34.1

複数バージョン共存している場合

Mac で Homebrew git と Xcode CLT git の両方がある、Linux で /usr/bin/git/usr/local/bin/git があるといった状況は珍しくありません。どの git が実行されているか確認:

# 実行されているパス
which git
# /opt/homebrew/bin/git

# 全候補を見たい (Linux)
which -a git
# /opt/homebrew/bin/git
# /usr/bin/git

# 詳細 (shell 関数 / alias まで)
type -a git
command -v git

# シンボリックリンクを辿る
ls -la $(which git)
readlink -f $(which git)

# PATH 順を確認
echo $PATH

最新版の確認 / 更新

# 最新版を調べる (GitHub)
curl -s https://api.github.com/repos/git/git/tags | head -20

# macOS (Homebrew)
brew update
brew upgrade git
brew info git           # インストール済情報

# Ubuntu / Debian
sudo apt update && sudo apt install -y git

# Ubuntu で最新の git (PPA)
sudo add-apt-repository ppa:git-core/ppa
sudo apt update && sudo apt install -y git

# Fedora / RHEL
sudo dnf install -y git

# Windows (winget)
winget upgrade Git.Git
# Windows (scoop)
scoop update git
# Windows (Chocolatey)
choco upgrade git -y

# WSL (Ubuntu)
sudo apt update && sudo apt install -y git

注意: git update という Git 公式コマンドは存在しません。アップデートは OS のパッケージマネージャ経由で行います。

Mac の Xcode CLT 同梱版が古い問題

macOS の /usr/bin/git は Xcode Command Line Tools 同梱で、1-2 年遅れのバージョンになっています:

# 2026 年 Apple Git の典型
git --version
# git version 2.39.5 (Apple Git-154)   ← 2.39 系は 2023 年

# Homebrew で最新化
brew install git

# PATH に Homebrew が前にあれば自動切替
echo $PATH
# /opt/homebrew/bin:/usr/bin:...

# .zshrc / .bashrc に
export PATH="/opt/homebrew/bin:$PATH"

# 確認
which git
git --version
# git version 2.45.1

機能の最低バージョン要件

新しいコマンドは古い Git にはありません。CI / チーム共有時には注意:

機能最低バージョンリリース時期
git switch / git restore2.232019-08
git sparse-checkout (新形式)2.252020-01
SHA-256 リポジトリ (実験的)2.292020-10
partial clone 安定化2.302020-12
default branch main2.282020-07
credential.helper=manager2.39 (Win)2022-12
scalar コマンド2.382022-10
git for-each-repo2.302020-12

CI / Dockerfile でのバージョンチェック

# CI スクリプトでのバージョンガード
required=2.23
current=$(git --version | sed 's/^git version //')

if [ "$(printf '%s\n%s' "$required" "$current" | sort -V | head -1)" != "$required" ]; then
    echo "git $required+ required, got $current"
    exit 1
fi

# GitHub Actions
- name: Show git version
  run: git --version

# Dockerfile
RUN git --version && \
    apt-get update && apt-get install -y git=1:2.39.* && \
    git --version

ChatOps / Slack / Teams での確認

Bot 経由で実行することも多い:

# Slack の Workflow で
/exec git --version

# GitHub Actions の workflow_dispatch
- run: git --version
- run: git config --list
- run: git log -1 --pretty=fuller

関連の確認コマンド

# Git 本体の場所と関連バイナリ
git --exec-path                # libexec のパス
ls $(git --exec-path)          # git-* サブコマンド一覧

# Git の設定ファイル位置
git config --list --show-origin

# Git LFS のバージョン
git lfs version

# Git Credential Helper
git config --global credential.helper
# manager (Windows), osxkeychain (Mac), store (Linux)

# Git Hooks ディレクトリ
git config core.hooksPath

FAQ

Q: git --version が動かない
A: PATH に git が無い、または Git 未インストール。インストール後に再ログイン or source ~/.bashrc

Q: バージョンを変更したいが PATH 設定が反映されない
A: シェル種別を確認 (echo $SHELL)。zsh は .zshrc、bash は .bash_profile / .bashrc。SSH ログインと GUI で参照ファイルが違う点も注意。

Q: 古い Git が必要 (CI の互換性確認等)
A: Docker で固定バージョン: docker run --rm alpine/git:v2.30.2 git --version。GitHub Actions では actions/checkout@v4 のオプション fetch-depth 等で挙動制御。

Q: Windows と WSL で git バージョンが違って混乱
A: それぞれ別物。git.exe (Windows) と Linux 側 git を別個に管理し、WSL 内では Linux 側を使うのが基本。