Clear Git History

So this site is hosted on codeberg who provide free hosting for open source repositories. With that being said they have limited resources at their disposal. So for that reason, I feel that I don’t need to keep the entire history of this site in source control. This is because it requires two branches, one with the markdown Hugo source, and the other being the HTML output which is rather large. So to keep this history down I’ve decided to remove all the history, and then make this a task that I’ll do every couple of months.

The steps are simple to clear all the history of a git branch. It’s simply creating a temp branch from the current branch which is an orphan1. Then delete the branch that you branched from, then rename the current temp branch to the same as the deleted branch. Finally, push the branch back up to the remote repository.

# assuming that the branch is main and remote is called origin
git pull
git checkout --orphan temp-branch
git add .
git commit -am "creating new initial commit"
git branch -D main
git branch -m main
git push -f origin main

Now going back to the web interface for your git repository you should now see that the number of commits on the main is now set to 1. Soon the size of the repository on disk should also reduce if your hosting solution shows that information.

It’s usually not recommended to rewrite or remove the history of a git repository, as it kind of defeats the point of having source control. However in this special use case, of a Hugo-generated site hosted on a free open-source platform with limited resources, I feel that doing this is worthwhile.

<-- Moving Away From Github
Prusa Mini Extrusion Troubleshooting -->