Git Push Blocked Resolution

User
remote: Your push has been blocked because it includes at least one file that is 100 MB or larger. Bitbucket Cloud recommends using Git LFS for large files to prevent repositories from growing too large and reaching the 4 GB repo size limit. Learn more about Git LFS at https://support.atlassian.com/bitbucket-cloud/docs/manage-large-files-with-git-large-file-storage-lfs/. If necessary, the file size limit can be disabled by an admin in Repository settings. Learn more at https://support.atlassian.com/bitbucket-cloud/docs/reduce-repository-size/#Avoid-adding-large-files.
To https://bitbucket.org/plstr-digital/solaron-wordpress-website.git
! [remote rejected] feature/solaron -> feature/solaron (pre-receive hook declined)
Assistant
The error indicates that your push was blocked because it contains a file that is 100 MB or larger. Bitbucket enforces this limit to prevent repositories from becoming too large. Here’s how you can address this issue:

### Steps to Resolve:

1. **Identify the Large File:**
Run the following command to find large files in your commit history:

git rev-list --objects --all | git cat-file --batch-check='%(objectname) %(objecttype) %(rest)' | sort -k 3 -n | tail -10

This will list the largest files in your repository.

2. **Remove the Large File from History:**
If you find a large file that should not be in the repository, you can use the `BFG Repo-Cleaner` or `git filter-repo` to remove it:
– Install BFG Repo-Cleaner:

brew install bfg  # For Mac

or download it from [BFG Repo-Cleaner](https://rtyley.github.io/bfg-repo-cleaner/).
– Run the BFG command:

bfg --delete-files <filename>

– Follow up with:

git reflog expire --expire=now --all && git gc --prune=now --aggressive

3. **Use Git LFS for Large Files:**
If the large file is necessary for your project (e.g., media, assets), use Git Large File Storage (LFS):
– Install Git LFS:

git lfs install

– Track the large file:

git lfs track "<filename>"

– Commit the `.gitattributes` file that Git LFS generates:

git add .gitattributes
     git commit -m "Track large files with Git LFS"

4. **Force Push to Update the Remote Repository:**
After cleaning up the repository or using Git LFS, you’ll need to force-push your changes:

git push origin --force

**Note:** Be cautious with force-push as it rewrites history and may affect collaborators.

5. **Prevent Large Files in the Future:**
Add a `.gitignore` file to prevent committing unnecessary large files:

*.zip
   *.mp4
   *.iso
   *.exe

You can also set up a pre-commit hook to block large files from being committed.

6. **Reattempt the Push:**
After addressing the issue, push your changes again:

git push origin feature/solaron

If you need help with any of these steps, let me know!

Leave a Comment

Your email address will not be published. Required fields are marked *