Gitlab-delete commit history

This article will teach how to delete the commit history on Gitlab.

Step 1: remove all history (Make sure you have backup, this cannot be reverted)

rm -rf .git

Step 2: reconstruct the Git repo with only the current content.

git init
git add .
git commit -m "Initial commit"

Step 3: push to GitHub.

git remote add origin <github-uri>
git push -u --force origin master

And then, if you get the message:

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

It's meaning your master had been protected, go to settings chick Repository and you will see the view below.

Find the master and choose Unprotect.

Then, try to push again if it can work your will only see the commit 'Initial commit' on your history.

Finally, remember to protect master if you success to delete history.