How to Delete Commit History in GitHub
21 October, 2022
20
20
1
Contributors
We often tend to add important details in GitHub when we create a Repository. Lets say if we are creating an account to setup AWS, we tend to add the secret-ID by mistake and even if we commit and replace it, it will be available in Commit History. To avoid this, the only way is to delete the commits history.There are ways to delete the Repository Commit History, adding one way among the others
There are ways to delete the Repository Commit History, adding one way among the others
Step 1:
Clone the repository to your terminal. Easy way to clone is paste the repo url and add (.git) at the end.
git clone https://github.com/Prannesh45/Private_repo.git
Step 2:
Create an Primary Orphan Branch. The following command creates a new branch "new_orphan_branch_name" and checks out to that branch
git checkout --orphan new_orphan_branch_name
Step 3:
Now do all the modifications, if you want to add any new file, modify any existing ones and then enter the following command to force commit.
git add -A
git commit -m "Initial Comment"
Step 4:
Now as we have created an orphan branch and committed the files, we can delete the main branch to your github repository.
git branch -D main
Step 5:
Now its time to rename the current branch to the main branch
git branch -m main
Step 6:
Now after we have renamed, time to push the local changes to the remotely present repository in GitHub
git push -f origin main
Now you have deleted the complete commit history and pushed it to main branch. You can login to GitHub in website and you will be able to see 0 changes in Commit History
That's it for today. Planning to write many more Shows and Series, so make sure to be in touch :)
github
hacktoberfest