I want to reset one of my repositories on gitlab, but without deleting the whole project.
I've read on Gitlab Forums (on the post https://forum.gitlab.com/t/how-can-i-delete-a-repository-and-push-a-new-one/690) two different options:
First: Deleting the physical repository from disk. I've tried renaming the folder (repo.git) but then, gitlab gives me a 404 error trying to access to it.
Second: Deleting all branches. This solution do not work too, because, I cannot delete the main branch (on my case master), and when I create a new one, the new branch requires to specify a "original" branch. I cannot create a clean branch without any data and change the main to it.
Someone know how to do it?
Thanks,
Restarting the server with gitlab-ctl restart releases the open files and frees the associated disk space. As a temporary workaround it's possible to do this periodically with a cron job or manual maintenance, but ideally Gitlab should be able to detect that a repack has occurred and close the old files itself.
Delete all branches except master
, unprotect master
in settings -> repository -> protected branches
and execute:
git push -f master origin
.
There is a workaround, and it works for me. At first, on project's settings/repository page change the default branch to a non-master branch, then delete the master branch and push the new files to master, at last change the default branch back to master and delete all the other branches you don't want.
I've been asking myself this same question, and running through the same issues you mentioned. I have repositories with a lot of crud in them that shouldn't have been there before which is why I wanted to do this. I can easily reduce my local repo to < 1MB and force push that to gitlab, however the hosted repo simply doesn't reduce in size (I presume artefacts remain in the repo). Moving all issues across to a new repo isn't an option either as the dates all get "today's" date and is cumbersome.
I think I've discovered a way though. First export your current repo and download the tar.gz file from gitlab (this contains the repo, issues etc). Then create / modify / whatever the new repo you wish to replace the existing one with. Once ready, create a bundle of that new repo, ie: the one you want (from within that repo):
git bundle create /tmp/project.bundle --all
Then replace the project.bundle
in the downloaded tar.gz with the new project.bundle
.
Now you can create a new project on gitlab by importing that tar.gz, and you should hopefully have all your issues, tags, etc from the original, but with the new repository.
Now you can rename your old and new repos and hopefully you should be good to go. It's not ideal I know, but in my case it was the issue history I wanted to keep, and a pruned version of the repo.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With