Home > Software design >  Reduce repository size | error: failed to push some refs to [remote]
Reduce repository size | error: failed to push some refs to [remote]

Time:11-23

I am stuck for 2 days trying to find a way to clean up my remote gitlab repo. I mistakenly push local repo after adding my data folder, which I forgot to include in the git-ignore. Since then, I cannot push any more, as the remote grows to 9.8GB, so I kept getting exceeded storage error.

I then completely removed the data folder fom my git-tracked repo. The resulting local repo is now about 12M size (python scripts and jupyter notebooks) only. Despite this clean-up, yet I cannot push to remove.

I followed the procedure outlined here.

  1. Cloned a fresh copy of my repository from using --bare and --mirror options:
$ git clone --bare --mirror my-repo.git
  1. And changed to cloned repo:
$ cd my-repo.git
  1. Purge all files larger than 10M:
$ git filter-repo --strip-blobs-bigger-than 10M
Processed 1306 blob sizes
Parsed 53 commits
New history written in 0.06 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
Enumerating objects: 1195, done.
Counting objects: 100% (1195/1195), done.
Delta compression using up to 8 threads
Compressing objects: 100% (910/910), done.
Writing objects: 100% (1195/1195), done.
Reusing bitmaps: 43, done.
Building bitmaps: 100% (51/51), done.
Total 1195 (delta 237), reused 1095 (delta 217), pack-reused 0
Completely finished after 6.89 seconds.
  1. Then delete this origin remote, and set the URL to my repository:
$ git remote remove origin
Note: A branch outside the refs/remotes/ hierarchy was not removed;
to delete it, use:
  git branch -d master
$ git remote add origin https://gitlab.com/my-repo.git
  1. Now I need to force push my changes to overwrite all branches on GitLab:
$ git push origin --force 'refs/heads/*'
Username for 'https://gitlab.com': [email protected]
Password for 'https://[email protected]@gitlab.com': 
Enumerating objects: 1195, done.
Writing objects: 100% (1195/1195), 275.18 MiB | 18.29 MiB/s, done.
Total 1195 (delta 0), reused 0 (delta 0), pack-reused 1195
remote: Resolving deltas: 100% (237/237), done.
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.com/my-repo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/my-repo.git'

This step failed! Unfortunately, all answers to this and this didn't help solve the problem.

What do you suggest?

CodePudding user response:

A silly suggestion have you tried changing remote on gitLab and removing the folder to reduce the size of the repo? https://gitlab.com/gitlab-org/gitlab-foss/-/issues/3518

CodePudding user response:

remote: GitLab: You are not allowed to force push code to a protected branch on this project.

That's your answer, right there. You commanded GitLab to update the name master. GitLab said: "No. You are not allowed."

Find out who is allowed and have them do it, or change the set of people who are allowed, or authenticate as a person who is allowed. Those are your options.

  • Related