0

Recently, I enabled git lfs for my gitlab project while checking in a 200 MB file. And this I could successfully and verify that in remote this new 200 MB file shows LFS.

In the past I had checked-in few 10 MB files without lfs. Those exist in remote too. What is the best way to migrate those to lfs?

I tried following:

git lfs migrate import --everything --include="*.pkl" --verbose

And then when I try git push, I get an error -

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'yourgit.internal.yourdomain.com:<user>/project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

git pull does not work either. What is the way to migrate existing files to lfs? Will adding --include-ref=refs/heads/master to the migrate command help?

And do I need to do anything extra for the other branches?

soumeng78
  • 600
  • 7
  • 12

1 Answers1

1

git lfs migrate import rewrites the branches. So, the branches in the local repository are diverged with the branches in the remote repository. That's why the push fails due to non-fast-forward. In this case, git pull is not suitable. It would merge the original branch and the rewritten one, making the effort of git lfs migrate import in vain. Instead, you need to force-push the local branches to the remote repository.

The repository size on Gitlab is not going to reduce significantly as the remote repository has some internal refs that reference to the old objects. But a new clone is expected to be much smaller than before.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • Thank you - I'll try `git push --force` and followed by `git gc --prune=now` to see if the repository size reduces. – soumeng78 Nov 30 '22 at 19:08
  • When I tried "git push -force", it gave me "pre-receive hook declined" error as the branch was protected, even though I was the owner of the repo. I, finally, made the branch unprotected to proceed. Was there any other alternative? And my 2nd question is do I need to run this "lfs migrate" for every branch? Please note I did use --everything switch in the migrate command. – soumeng78 Jan 11 '23 at 19:30
  • --everything seems to work while trying from other branches but not from 'master'. – soumeng78 Jan 12 '23 at 06:53
  • @soumeng78 If force push fails, the branch is protected. Ask the repository owner for help. – ElpieKay Jan 13 '23 at 01:37
  • I am the owner of the git lab project. I just enabled the force push option and checked in. – soumeng78 Jan 13 '23 at 01:51