|
The Git History Reset Script is a tool designed to reset commit history in Git repositories, offering a fresh start without traces of previous versions. Ideal for developers needing to hide sensitive information or reorganize repository history, this script provides a quick, secure, and efficient way to wipe the history while preserving project content. With a straightforward interface, Git History Reset Script ensures security and integrity, making it the perfect choice for freelancers, collaborative development teams, and those managing public repositories, delivering hassle-free repository management. |
main.master branch to main.
.
βββ .github/ # GitHub configuration files
βββ README.md # Project documentation
βββ reset_git_history.sh # Script to reset commit history
βββ LICENSE # Project license
git clone https://github.com/MuriloKrominski/Reset-Git-History-Script.git
Navigate into the repository:
cd Reset-Git-History-Script
Run the script:
bash reset_git_history.sh
#!/bin/bash
# Check if the current folder is a Git repository:
if [ ! -d .git ]; then
echo "This directory does not appear to be a Git repository."
exit 1
fi
# Ask the user if they really want to remove the commit history:
read -p "Are you sure you want to remove the commit history? [y/n] " confirm
if [ "$confirm" != "y" ]; then
echo "Action canceled."
exit 0
fi
# Get the current remote repository:
REPO_URL=$(git config --get remote.origin.url)
if [ -z "$REPO_URL" ]; then
echo "Could not find the remote repository. Make sure this repository has 'origin' configured."
exit 1
fi
# Remove the commit history:
rm -rf .git
# Initialize a new Git repository:
git init
# Add all files to the new repository:
git add .
# Create the first commit:
git commit -m "First commit without previous history"
# Rename the branch to 'main':
git branch -M main
# Add the remote repository:
git remote add origin $REPO_URL
# Force push to the remote repository:
git push --force origin main
# Ask if the user wants to delete the 'master' branch:
read -p "Do you want to delete the 'master' branch on the remote? [y/n] " delete_master
if [ "$delete_master" == "y" ]; then
git push origin --delete master
echo "Master branch deleted on the remote repository."
else
echo "Master branch was not deleted."
fi
echo "Commit history removed and new repository pushed to GitHub on the 'main' branch."
# Pause the script to allow the user to see the result:
read -p "Press any key to exit..."
This script force-pushes changes to your remote repository. Make sure you understand the implications before using it, as it can overwrite your repositoryβs history permanently.
This project is licensed under the MIT License.
Anyone can clone and contribute with improvements to the public beta version "Ξ² (PUBLIC)".
Financially support open-source code and help build a more collaborative and innovative future, where knowledge is shared, and progress is collective.
Your sponsorship helps developers, like me, dedicate more time to developing new projects, new features, bug fixes, and keeping everything up to date.