2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

git push 時の HTTP 400 エラーの対処法

Last updated at Posted at 2025-05-22

はじめに

git pushコマンド実行時に以下のようなエラーメッセージが表示されました。今回は、このエラーの原因と解決策をまとめます。

Enumerating objects: 4368, done.
Counting objects: 100% (4368/4368), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4144/4144), done.
Writing objects: 1% (83/4367), 112.00 KiB | 57.00 KiB/s
error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400
fatal: the remote end hung up unexpectedly
Writing objects: 1% (83/4367), 1.07 MiB | 447.00 KiB/s

エラーの原因

GitがHTTPプロトコルを使用してデータを送信する際のバッファサイズがデフォルト(約1MB)では小さすぎるため発生したようです。
今回は、node-modulesなどの容量の大きなディレクトリが含まれていたことが原因でした。

長期間コミットせずに多くの変更を行った場合も、同様のエラーが発生することがあります

解決方法

そこでとった対応は、以下の2点です。

  • .gitignoreに大容量のディレクトリを追記
  • Gitのバッファサイズを増やす

.gitignorenode-modulesなどのディレクトリを追記しました

.gitignore
node_modules/
.next/

そして、一時的な対応としてHTTPプロトコル経由でのデータ送信に使用されるバッファサイズを 約500MB に設定しました。

git config http.postBuffer 524288000

上記のコマンドを実行し、改めてgit pushしたところ無事成功しました!

git push -u origin main

Writing objects: 100% (4367/4367), 18.24 MiB | 3.76 MiB/s, done.
Total 4367 (delta 1186), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1186/1186), done.

その他の解決方法

バッファサイズの調整でも解決しない場合は、以下の方法もあるようです。

  • 分割してプッシュする
  • HTTPSの代わりにSSHプロトコルを使用する

まとめ

これまでは機械的に .gitignorenode_modules を記載していましたが、今回のエラーを通じてその必要性を改めて理解しました。

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?