Git error: ! [remote rejected] main -> main (pre-receive hook declined)
Git error:
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop (main)
$ git push -uf origin main
Enumerating objects: 12491, done.
Counting objects: 100% (12491/12491), done.
Delta compression using up to 8 threads
Compressing objects: 100% (9964/9964), done.
Writing objects: 100% (12491/12491), 170.55 MiB | 2.76 MiB/s, done.
Total 12491 (delta 2152), reused 12491 (delta 2152), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2152/2152), done.
remote: GitLab: You are attempting to check in one or more blobs which exceed the 100.0MiB limit:
remote:
remote: - 6bfcacdc692350a9c53caf39a4c3d590ab2bbdef (118 MiB)
remote: To resolve this error, you must either reduce the size of the above blobs, or utilize LFS.
remote: You may use "git ls-tree -r HEAD | grep $BLOB_ID" to see the file path.
remote: Please refer to https://gitlab.com/help/user/free_push_limit and
remote: https://gitlab.com/help/administration/settings/account_and_limit_settings
remote: for further information.
To https://gitlab.com/******/******.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/******/******.git'
I already tried to unprotect my main branch and re-push but still get similar error.
The error message you're encountering indicates that you are trying to push a file that exceeds GitLab's 100MB file size limit. To resolve this issue, you have a couple of options:
Reduce the size of the file: If possible, you can try to compress or otherwise reduce the size of the file that is over 100MB.
Use Git Large File Storage (LFS): Git LFS is designed to handle large files by storing them outside of your main repository and only keeping pointers to the files in your repository. Here’s how you can set up Git LFS and push your large file:
Step-by-Step Solution Using Git LFS
Install Git LFS:
If you haven't already installed Git LFS, you can do so by following the instructions on the Git LFS website.
Initialize Git LFS in your repository:
git lfs install
Track the large file(s) with Git LFS:
Replace path/to/largefile with the path to your large file.
git lfs track "path/to/largefile"
Add the .gitattributes file to your repository:
Git LFS will create a .gitattributes file to track the large files. Add this file to your repository.
git add .gitattributes
Add and commit your large file(s):
git add path/to/largefile
git commit -m "Add large file using Git LFS"
Push your changes to the remote repository:
git push origin main
Example
Here’s an example of how you might handle a large file named largefile.zip:
Install Git LFS:
git lfs install
Track the large file:
git lfs track "largefile.zip"
Add the .gitattributes file:
git add .gitattributes
Add and commit the large file:
git add largefile.zip
git commit -m "Add large file using Git LFS"
Push the changes:
git push origin main
By following these steps, you should be able to push your large file to GitLab without encountering the pre-receive hook error.
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop_single (main)
$ git lfs install
Updated Git hooks.
Git LFS initialized.
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop_single (main)
$ git lfs track /d/xampp81/htdocs/foodshop_single
Tracking "D:/xampp81/htdocs/foodshop_single"
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop_single (main)
$ git add .gitattributes
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop_single (main)
$ git add /d/xampp81/htdocs/foodshop_single
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop_single (main)
$ git commit -m "Add large file using Git LFS"
On branch main
nothing to commit, working tree clean
davy_@DESKTOP-2I1L6PU MINGW64 /d/xampp81/htdocs/foodshop_single (main)
$ git push -uf origin main
Locking support detected on remote "origin". Consider enabling it with:
$ git config lfs.https://gitlab.com/******/******.git/info/lfs.locksverify true
Enumerating objects: 12494, done.
Counting objects: 100% (12494/12494), done.
Delta compression using up to 8 threads
Compressing objects: 100% (9966/9966), done.
Writing objects: 100% (12494/12494), 170.50 MiB | 2.57 MiB/s, done.
Total 12494 (delta 2155), reused 12489 (delta 2153), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2155/2155), done.
remote: GitLab: You are attempting to check in one or more blobs which exceed the 100.0MiB limit:
remote:
remote: - 6bfcacdc692350a9c53caf39a4c3d590ab2bbdef (118 MiB)
remote: To resolve this error, you must either reduce the size of the above blobs, or utilize LFS.
remote: You may use "git ls-tree -r HEAD | grep $BLOB_ID" to see the file path.
remote: Please refer to https://gitlab.com/help/user/free_push_limit and
remote: https://gitlab.com/help/administration/settings/account_and_limit_settings
remote: for further information.
To https://gitlab.com/******/******.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/******/******.git'