Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset / clean a GitLab repository

Tags:

gitlab

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,

like image 765
Sakura Kinomoto Avatar asked Dec 14 '18 01:12

Sakura Kinomoto


People also ask

How do I free up space on my GitLab server?

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.


3 Answers

Delete all branches except master, unprotect master in settings -> repository -> protected branches and execute:

git push -f master origin .

like image 105
stakahop Avatar answered Sep 19 '22 03:09

stakahop


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.

like image 41
Jack Avatar answered Sep 21 '22 03:09

Jack


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!

like image 36
Axllent Avatar answered Sep 21 '22 03:09

Axllent