0

We currently have a repo with around 40,000 commits and it's starting to have issues with gitlab, specifically with failing the weekly health check. It's a pretty old repo that's been running for years.

Since starting a new project would result in a new project ID causing issues with our issue tracker, would it be possible / a reasonable idea to do something like the following:

  1. Create a new project, push the current repo into that project (just as a backup)
  2. Create a temp branch based on master
  3. Delete master, create new master branch
  4. merge --squash the temp branch back into the master branch

No one works directly on master and it's only used for deployment. When a MR is accepted, it gets squash merged into master, some files are updated, and a new tag is stamped with the next version id. All running processes use the tag as a checkout point instead of just the master branch.

In the end, would this do anything to help, or just mess things up?

GameCharmer
  • 614
  • 1
  • 7
  • 20
  • Once you have completed Step 2, you can follow [this SO post](https://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch) for ways to override `master` with `temp` branch, if I understood your requirements correctly. – Asif Kamran Malick Mar 29 '21 at 16:16
  • That's not quite what I had in mind @AsifKamranMalick. I'd like to eliminate the thousands of commits long history on master and just stick it somewhere else without creating a new project in gitlab. – GameCharmer Mar 29 '21 at 17:49
  • As a backup you can create a branch based on master. Then checkout the `master` branch and do the following steps: `git checkout --orphan my-orphaned-master` --> `git commit -m ""` --> `git branch -D master` --> `git branch -m master` --> `git push -u --force origin master` . This worked for me . Hopefully it should work for you too. In the end you have a backed-up master and your master should have just one commit. – Asif Kamran Malick Mar 29 '21 at 19:32

1 Answers1

1

As suggested by Asif Kamran Malick, an orphan branch can help:

  • Checkout your old main/master
    git checkout master
  • Create a backup branch
    git checkout -b backup
  • Delete the old master branch (so we can use the same name)
    git branch -D master
  • Create a new master branch without any history
    git checkout --orphan master
  • Add your latest files / code to this new branch (in my quick test the checkout kept all files in the working dir)
    git commit --all -m "Add latest files in one fresh commit"
  • Push the new master to your Git server like Github/Gitlab/… (you might have to delete it first on the remote or force push if possible)

Still, this is a rather rough procedure, so make sure all collegues use the new master for new features (otherwise you'll merge in all the history again) and be ready to deal with hickups in the transition period.

orzechow
  • 1,210
  • 2
  • 13
  • 18