My team and I are investigating the possibility to use a workflow on GitLab that seems to be quite popular on GitHub. This workflow consists in squashing branches when merging to have a clean main
branch with a single commit per feature/bugfix.
Since we started using GitLab, we haven’t been doing that simply because GitLab doesn’t have GitHub’s “Restore Branch” functionality in the UI, so instead we never squash in order to keep the history of each branch in case we need to do some archeology (i.e. git bisect
).
I recently re-investigated the possibility to do that in GitLab, and there is an open issue to add that in the UI, but I also found a workaround on stackoverflow. It consists in creating a new branch and providing the hash of the branch head, and then GitLab should be able to retrieve all the commits of that branch. However, this only works if:
you know the commit ID (and it hasn’t been pruned)
(emphasis is mine)
This led me down the path of trying to understand when a commit might be pruned by GitLab, and I did find the page on housekeeping in the documentation, especially the part on unreachable objects. These are getting pruned with a grace period which depends on whether housekeeping was manually or automatically triggered.
The part that confuses me is that after playing around with MRs for a little over 2 weeks, it seems like deleted branches that were part of an MR are not pruned at all, I can still recover the branches after more than 2 weeks and after making additional commits that should trigger housekeeping. I researched that a bit and found that GitLab introduces keep-around refs related to comments/merge-requests/environments/pipelines that prevent stuff from being deleted.
So in the end, my question is: if I have a branch related to an MR, and during merging I squash the commits and delete the branch, will I be able to indefinitely recover the branch using the workaround I mentioned above? It sounds like this is the case because of keep-around refs, but I would like to make sure it is because I cannot get a clear answer from the docs.