initialize entire commit log
Overview
This guide shows how to delete (reset) the entire commit history of a repository.
If sensitive data like images, IDs, or passwords are exposed in your public repository, you can use this method to wipe all commit history and stay safe.
Background
How it works
The idea behind resetting commit history is simple.

- Create a new branch called latest_branch from main.
- Delete the old main branch.
- When the old main branch is deleted, all commit logs inside it are also deleted.
- Rename latest_branch to main.
- Push the new main branch to the remote.
You must run these steps in a local clone of the repository.
Warnings
Commit log deletion
- Following this guide will erase all commit history on the main branch. There is no way to recover deleted commit logs.
Limitation
This limitation only applies to public repositories. Even after deleting all commits, the Activity records remain on GitHub. Anyone can still view the diff of each commit through Activity records.
- According to GitHub Support, public activity is not deleted unless sensitive information is exposed. This is a policy to keep repository transparency and change history. However, GitHub's Secret Scanning feature is enabled by default, so pushes containing secret keys or tokens are rejected. Secret Scanning helps a lot, but you still need to stay careful.
- There is a feature request to restrict Activity visibility to specific people at Repository Activity View #53140.
Prerequisites
You need git installed on your local machine.
$ git --version
git version 2.37.1 (Apple Git-137.1)Solution
There are two ways to reset commit history:
- Using git commands manually
- Running a pre-built script
Using git commands
Checkout
Create a new branch called latest_branch.
# [>] main
git checkout --orphan latest_branchThe checkout --orphan command creates a new branch with no commit history.
Add all files
Add all files to the new latest_branch branch.
# [ ] main
# [>] latest_branch
git add -AThe -A flag stages all files.
# [ ] main
# [>] latest_branch
git commit \
-m "Initial commit" \
-m "Initialize repository to clean all commit history using commit history cleaner script"Commit all files to the new latest_branch branch.
Delete branch
Delete the old main branch.
# [X] main
# [>] latest_branch
git branch -D mainWhen the old main branch is deleted, all its commit logs are deleted too.
Rename branch
Rename latest_branch to main.
# [>] latest_branch --> main
git branch -m mainThe -m flag renames the branch.
Force push
# [>] main
git push -f origin mainForce push the new main branch to the remote.
Verify
Check the commit log on the new main branch.
# [>] main
git log --graph
# Display commit history as a one-line summary with a graph
git log --oneline --graphThe --graph flag shows the commit log as a tree.
The output looks like this:
* commit 4xxx81728xx4x8815f6970f43545b3xxx433x2x3 (HEAD -> main, origin/main, origin/HEAD)
Author: younsl <cysl@kakao.com>
Date: Fri Feb 24 17:33:33 2023 +0900
Initial commitAll previous commit logs are gone. Only the initial commit remains.
No one can see the exposed sensitive information in commit logs anymore.
Commit history reset is complete.
Using a script
First, navigate to the git directory where you want to reset commit history.
Download the commit history cleaner script from GitHub.
wget -O commit-history-cleaner.sh \
https://raw.githubusercontent.com/younsl/dotfiles/refs/heads/main/scripts/git/commit-history-cleaner.shCheck the downloaded file.
ls -lh commit-history-cleaner.sh-rw-r--r--@ 1 john.doe staff 1.7K Feb 4 04:33 commit-history-cleaner.shRun the script.
sh commit-history-cleaner.shThe script asks for confirmation. Type y to delete all commit logs on the main branch.
Warning: This is a destructive operation that deletes all commit logs on the main branch. You cannot undo this.
This script will delete the main branch and create the latest_branch branch.
Do you want to continue? (yY/n) yVerify the result.
# Display commit history as a one-line summary with a graph
git log --oneline --graphCommit history reset is complete.
Conclusion
Do not use rm -rf .git to delete the .git directory. It contains submodule settings and other repository configs. Deleting it is risky and hard to recover from.
The goal is to wipe commit history, not the entire repository setup. A much simpler and safer approach is to copy main to a new branch, delete the old main, and rename the new branch. Remember: when a branch is deleted, all commit logs inside it are deleted too.
References
Github: