git pull コマンドは、リモートリポジトリの更新を取得して現在のブランチに統合するコマンドです。
内部的には git fetch + git merge が行われます(オプションにより rebase も可能)。
構文(Syntax)
git pull [オプション] [リモート名] [ブランチ名]
主なオプション一覧
| オプション | 説明 | 使用例 |
|---|---|---|
| (なし) | 現在のブランチの追跡先から取得してマージ | git pull |
<リモート> <ブランチ> | 指定リモート・ブランチを取得して統合 | git pull origin main |
--rebase | マージの代わりにリベースを実行 | git pull --rebase origin main |
--ff-only | Fast-forward のみ許可(競合があればエラー) | git pull --ff-only |
--no-commit | マージコミットを作成するが、まだコミットしない | git pull --no-commit origin develop |
--all | 登録されているすべてのリモートから取得 | git pull --all |
実行例
基本的なプル(fetch + merge)
git pull
出力例:
Updating abc123..def456
Fast-forward
file1.txt | 2 ++
リモートとブランチを指定して取得
git pull origin develop
リベースして統合
git pull --rebase origin main
Fast-forward のみ許可
git pull --ff-only origin main
マージは行うがコミットしない
git pull --no-commit origin feature-x
すべてのリモートから取得
git pull --all
コンフリクト発生時の例
git pull origin main
出力例:
Auto-merging app.py
CONFLICT (content): Merge conflict in app.py
Automatic merge failed; fix conflicts and then commit the result.
解決後:
git add app.py
git commit
エラー例(リポジトリ外で実行)
git pull
出力例:
fatal: not a git repository (or any of the parent directories): .git
関連コマンド
git fetch: リモートの更新を取得するが統合はしない。git merge: 他のブランチを現在のブランチに統合する。git rebase: 更新をリベース方式で取り込む。
備考
git pullのデフォルト動作はfetch + mergeですが、設定でfetch + rebaseに変更することも可能:git config --global pull.rebase truegit pullは便利ですが、変更が競合しやすいため、大規模開発ではgit fetchとgit mergeを分けて実行する運用も推奨されます。- CI/CD など自動化スクリプトでは
--ff-onlyを利用すると安全です。
参考
- Git公式ドキュメント: https://git-scm.com/docs/git-pull

コメント