debugbashgitMajorpending
Debug: Git large file causing push rejection
Viewed 0 times
large filepush rejectedfilter-repobfggit lfshistory rewrite
Error Messages
Problem
Git push rejected because repository contains a file that exceeds the hosting provider's size limit, even after deleting the file.
Solution
The file is still in git history. Remove it completely:
Pre-commit hook to prevent large files:
# 1. Find large files in history
git rev-list --objects --all | \
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | \
sort -k3 -n -r | head -20
# Or use git-filter-repo (recommended tool)
pip install git-filter-repo
git filter-repo --analyze
cat .git/filter-repo/analysis/blob-shas-and-paths.txt | head -20
# 2. Remove file from entire history
# Option A: git-filter-repo (fast, recommended)
git filter-repo --path large-file.zip --invert-paths
# Option B: BFG Repo Cleaner (simpler syntax)
java -jar bfg.jar --delete-files large-file.zip
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# 3. Force push (required after rewriting history)
git push --force-with-lease
# Prevention: use .gitignore and Git LFS
echo '*.zip' >> .gitignore
echo '*.tar.gz' >> .gitignore
# For files that need version control:
git lfs install
git lfs track '*.psd'
git lfs track '*.zip'
git add .gitattributesPre-commit hook to prevent large files:
# .git/hooks/pre-commit
hard_limit=50000000 # 50MB
for file in $(git diff --cached --name-only); do
size=$(wc -c < "$file" 2>/dev/null || echo 0)
if [ $size -gt $hard_limit ]; then
echo "Error: $file is $(($size/1000000))MB (limit: 50MB)"
exit 1
fi
doneWhy
Git stores every version of every file forever. Deleting a large file from the working tree doesn't remove it from history - it's still in every clone.
Context
Git repositories with accidentally committed large files
Revisions (0)
No revisions yet.