git pull が「Your local changes would be overwritten」でできない
Your local changes would be overwritten は、未コミットの変更と pull の差分が同じファイルにあると出る。
commit か git stash で退避してから pull すれば直る。
公開: 更新:
git pull origin main … error: Your local changes to the following files would be overwritten by merge: f.txt Please commit your changes or stash them before you merge. Aborting
git pull origin main From /tmp/tmp.jiCgfE/remote * branch main -> FETCH_HEAD Updating c50e0d3..2624633 Fast-forward f.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
2026-08-02 に alpine/git で実際に打って取った出力。検証環境の詳細
要約
error: Your local changes to the following files would be overwritten by merge は、未コミットのローカル変更と、pull で取り込む変更が同じファイルを触っている ために、git が安全装置として merge を止めた状態である。
ローカルの変更を commit するか git stash で退避してから git pull すれば進む。
捨ててよい変更なら git restore で消す。
実行例
alpine/git 環境(git 2.54.0)で上記手順を実際に動かすと、f.txt の先頭行をローカルで未コミットのまま編集した状態で git pull を実行した時点で error: Your local changes to the following files would be overwritten by merge が発生し、終了コード 1 で中断した。
その後 git stash で退避してから pull・stash pop を順に実行すると、終了コード 0 で完了した。
末尾行の上流変更と先頭行のローカル変更は別の箇所なので、衝突なく適用された。
warning: You appear to have cloned an empty repository.$ git pull origin main
From /tmp/tmp.jiCgfE/remote
* branch main -> FETCH_HEAD
c50e0d3..2624633 main -> origin/main
Updating c50e0d3..2624633
error: Your local changes to the following files would be overwritten by merge:
f.txt
Please commit your changes or stash them before you merge.
Aborting
$ echo $?
1$ git stash push -m "before pull"
Saved working directory and index state On main: before pull
$ echo $?
0$ git pull origin main
From /tmp/tmp.jiCgfE/remote
* branch main -> FETCH_HEAD
Updating c50e0d3..2624633
Fast-forward
f.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ echo $?
0$ git stash pop
Auto-merging f.txt
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: f.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (4a2186a680b6014606397d7fcc6a8d840dae7e40)
$ echo $?
0$ git status --short
M f.txt$ cat f.txt
HEADER-LOCAL
a
b
c
d
FOOTER-UPSTREAM— 2026-08-02 時点の出力
検証環境2026-08-02 検証
- 検証日
- 実行環境
alpine/git
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. 変更を commit してから pull
git add -A
git commit -m "wip"
git pull残したい変更なら、この方法が最も素直である。
pull 後にコンフリクトが出たら通常の merge 解消に移る。
2. stash で退避する
git stash push -m "before pull"
git pull
git stash popコミットするほど固まっていない作業は stash で逃がす。git pull の挙動は git-pull 公式ドキュメント(新しいタブで開く) に、退避の詳細は git-stash ドキュメント(新しいタブで開く) に記載がある。pop で衝突したら解消後に git stash drop する。
3. 変更を破棄する
git restore path/to/file # 特定ファイルだけ捨てる
git restore . # 全部捨てる(取り返せないので注意)
git pullこの方法は、不要な変更だと確信できる場合に限って使う。restore は元に戻せないため、対象を限定して打つ。
4. そもそも追跡から外す
echo "dist/" >> .gitignore
git rm -r --cached dist
git commit -m "stop tracking build output"生成物や個人設定が原因なら、追跡をやめれば再発しない。
これが根本対策になることが多い。
よくある原因
- 編集中のファイルが衝突している。
自分が直しているファイルを、リモート側も更新していた。 - 追跡対象を誤っている。
ビルド生成物や.envをコミット対象にしてしまい、毎回差分が出る。 - 改行や権限に差分がある。
CRLF/LF や実行ビットの違いで、実質変更していないのに変更扱いになる。 - 履歴が書き換えられた。
共有ブランチへの force push で、差分の範囲が想定より広がっている。