US flag for language switch Brazilian flag for language switch Italian flag for language switch Argentinian flag for language switch Chinese flag for language switch Russian flag for language switch Israeli flag for language switch Korean flag for language switch Japanese flag for language switch German flag for language switch Indian flag for language switch French flag for language switch Egyptian flag for language switch

autor
By Murilo Krominski
Autor Repository Ξ² (PUBLIC)

Git History Reset Script

Star this Repo GitHub Contributors License: MIT Download Script Sponsor this project

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.

process

πŸš€ Key Features:

🎯 Use Cases:

πŸ“‚ Repository Structure:

.
β”œβ”€β”€ .github/                 # GitHub configuration files
β”œβ”€β”€ README.md                # Project documentation
β”œβ”€β”€ reset_git_history.sh     # Script to reset commit history
└── LICENSE                  # Project license
    

πŸ”§ How to Use:

    Download or clone this repository to your local system.
    
            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
        

πŸ‘¨πŸ»β€πŸ’» Script Code [100%]:


        #!/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..."
    

⚠️ Warning:

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.

πŸ“œ License:

This project is licensed under the MIT License.

🀝🏻 Collaborations:

Anyone can clone and contribute with improvements to the public beta version "Ξ² (PUBLIC)".

πŸ’– Sponsorships:

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.