• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Delete Commit History in Github

Written by Rahul, Updated on October 17, 2019
GIT commit, git, remove, Repository

This tutorial will help you to delete commit history from your local git repository and remote git repository hosted on Github, Gitlab, Bitbucket or any other git hosting. In this repository, you will remove the local master branch and create a new master branch. Finally, push changes to the remote git repository.

Delete Commit History in Github Repository

Follow the below steps to complete this task.

Warning: This will remove your old commit history completely, You can’t recover it again.
  • Create Orphan Branch – Create a new orphan branch in git repository. The newly created branch will not show in ‘git branch’ command.
    git checkout --orphan temp_branch
    
  • Add Files to Branch – Now add all files to newly created branch and commit them using following commands.
    git add -A
    git commit -am "the first commit"
    
  • Delete master Branch – Now you can delete the master branch from your git repository.
    git branch -D master
    
  • Rename Current Branch – After deleting the master branch, let’s rename newly created branch name to master.
    git branch -m master
    
  • Push Changes – You have completed the changes to your local git repository. Finally, push your changes to the remote (Github) repository forcefully.
    git push -f origin master
    

Reference: http://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-github

Share it!
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Related Posts

  • How to ignore file permission changes in git

    November 20, 2019
  • How to Clone Specific Git Branch from Remote Repository

    March 23, 2019
  • How to Rename Local and Remote Git Branch

    February 5, 2019
  • How to Install Gitlab Server on Ubuntu 18.04 & 16.04 LTS

    September 1, 2017
  • How to Setup Commit Username and Email for Git

    June 27, 2017

10 Comments

  1. Avatar Akash Reply to Akash
    October 26, 2019 at 11:15 pm

    Great! Thanks 🙂

  2. Avatar Horatio Reply to Horatio
    August 11, 2019 at 5:32 am

    Salute!

  3. Avatar João Reply to João
    July 19, 2019 at 2:08 am

    Thank you!

  4. Avatar rosen Reply to rosen
    July 16, 2019 at 11:00 am

    i love you. i couldnt remove sensitive data from the repo because i burried it with more commits and nothing else worked until i found this <3

  5. Avatar Ondřej Reply to Ondřej
    June 10, 2019 at 10:14 am

    Thanks, this helped. However, the remote server still keeps the old commits and they may be accessible, e.g. from web GUI or by commit hash. This is a problem if you accidentally commited a password.

    The fix is to ssh into the bare repo and run `git gc –prune=now`. That should drop them.

  6. Avatar Grateful Reply to Grateful
    June 7, 2019 at 7:46 am

    Works like a charm. Thank you!

  7. Avatar Jack Reply to Jack
    June 1, 2019 at 11:04 pm

    Thanks!

  8. Avatar Bro Reply to Bro
    May 15, 2019 at 9:37 pm

    Excellent.

  9. Avatar jason Reply to jason
    April 13, 2019 at 1:52 am

    Thanks

  10. Avatar Ralph Reply to Ralph
    June 27, 2018 at 4:41 pm

    Thanks.

Leave a Reply

Cancel reply

Popular Posts

  • How to Install Python 3.8 on Ubuntu, Debian and LinuxMint
  • How to Restart Network Service on CentOS 8 or RHEL 8
  • How to Check IP Address on CentOS 8
  • How to Install Java 11/8 on Amazon Linux
  • How to Configure Static IP on CentOS 8 (CLI)
Copyright © 2013-2019 TecAdmin.net. All Rights Reserved. This site uses cookies. By using this website you agree with our term and services
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkNo
Revoke cookies