Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Git error: GH001: Large files detected. You may want to try Git Large File

Uncategorized

Errors

C:\RajeshAll\github\ppt>git push origin master
Enumerating objects: 750, done.
Counting objects: 100% (694/694), done.
Delta compression using up to 8 threads
Compressing objects: 100% (584/584), done.
Writing objects: 100% (634/634), 606.82 MiB | 2.37 MiB/s, done.
Total 634 (delta 157), reused 15 (delta 1), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (157/157), completed with 42 local objects.
remote: error: Trace: f7d8654f7202cd414ba887663661bdefcad7e457d2abeecfdeb2a7777bdc31a1
remote: error: See https://gh.io/lfs for more information.
remote: error: File azure/slides/azure-getting-started/Session-1.pdf is 425.95 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To github.com:rajeshkumarin/ppts.git
 ! [remote rejected]     master -> master (pre-receive hook declined)
error: failed to push some refs to 'github.com:rajeshkumarin/ppts.git'

Solution

To remove Session-1.pdf from your commit in Git, follow these steps:

Revert the Commit: If the commit containing Session-1.pdf has not been pushed to the remote repository, you can use the following command to undo this commit while keeping the changes in your working directory:

$ git reset --soft HEAD~1

This command will move the current HEAD back to the previous commit, but keep the changes in your staging area.

Remove the File: Once the commit is undone, you need to remove the file from the staging area:

$ git reset HEAD azure/slides/azure-getting-started/Session-1.pdf

This command unstages Session-1.pdf but leaves it in your working directory.
Commit Again: Now, commit your changes again, excluding Session-1.pdf:


$ git commit -m "Your commit message"

Deal with the File Separately: If you still need to track Session-1.pdf but it is too large for GitHub, consider using Git Large File Storage (LFS). Install Git LFS and then set up LFS for your file types:


$ git lfs install
$ git lfs track "*.pdf"
$ git add .gitattributes

After setting up Git LFS, add your large file:


$ git add azure/slides/azure-getting-started/Session-1.pdf
git commit -m "Add large file with LFS"
Push Your Changes: Finally, push your changes to the remote repository:


$ git push origin master

Other Methods

there are alternative ways to remove a large file from your Git history, including using git filter-branch and using interactive rebase. These methods are generally less efficient or more manual but may work if you’re unable to use git-filter-repo or BFG.

Method 1: Using git filter-branch (Older, but Effective)
git filter-branch can rewrite Git history by removing the file from all commits, but it’s slower and more prone to errors in larger repositories. Here’s how to use it:

Run git filter-branch to Remove the File

$ git filter-branch --force --index-filter "git rm --cached --ignore-unmatch events.zip" --prune-empty --tag-name-filter cat -- --all

Replace events.zip with the name of your large file.

Clean Up and Force Push

Run the following to clean up your repository:

$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --prune=now --aggressive

Finally, force push the changes to GitHub:

$ git push origin --force --all

Note: This method modifies the entire history of the repository, so collaborators will need to re-clone or reset their repositories after this.
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x