#!/usr/bin/env bash
help_text="
NAME
repo-remove-history - Remove entire commit history from the current Git repo and push to origin.
USAGE
repo-remove-history [options]
OPTIONS
-h|--help
Show help text.
DESCRIPTION
Remove entire commit history from the current Git repo and push to origin.
AUTHOR
Martin N 2025
"
help_line="Remove entire commit history from the current Git repo and push to origin"
web_desc_line="Remove entire commit history from the current Git repo and push to origin"
try="Try ${0##*/} -h for more information"
tmp="${help_text##*USAGE}"
usage=$(echo "Usage: ${tmp%%OPTIONS*}" | tr -d "
" | sed "s/ */ /g")
while [[ "$1" != "" ]]; do
case $1 in
-h|--help)
echo "$help_text"
exit
;;
?*)
break
;;
esac
shift
done
echo "This removes the history from the current repo and pushes/commits this to the origin"
echo
read -p "Are you sure you want to continue [yN]? " yn
if [[ ${yn^^} != Y ]]; then
exit
fi
echo Resetting
echo
# Create a new branch and push.
git checkout --orphan fresh-start
git add -A
git commit -m "Initial commit"
# Delete main, rename fresh-start to main and push.
git branch -D main
git branch -m main
git push -f origin main