Oh Dear! monitors your entire website, not just the homepage. You'll get a notification as soon as your website is down, a monthly uptime report, a warning a few days before your SSL certificate expires and much more! Start your free 10 day trial now!

Remove all history from a GitHub repository

Original – by Freek Van der Herten – 2 minute read

From time to time I need to remove all history from a GitHub repository, for instance right before releasing a package I've worked on in private. Sometimes I don't want people to see all mistakes I've made along the way :-).

Here are the steps I perform:

# clone the repo (skip if you already have a cloned repo locally)
git clone git@github.com:USERNAME/REPOSITORY.git
cd REPOSITORY

# remove all history locally
rm -rf .git

# create a new local repo
git init

# add everything
git add .
git commit -m "First commit"

# nuke history on GitHub (irreversable)
git remote add origin git@github.com:USERNAME/REPOSITORY.git
git push -u --force origin master

That -u flag will automatically set tracking. That --force option will make GitHub accept your push even though the history of the repo they have is unrelated to the empty history that is being pushed.

Be aware that this will also close all PRs. Any links to specific comments you might have will not work anymore. If you're working on the repo with other people, inform that history has been deleted (or even better, ask them if it's ok to delete the history before you do that), they will have clone the repo again.

UPDATE: meanwhile Bram Van Damme shared a few nice, shorter, alternatives to achieve the same goal.

Stay up to date with all things Laravel, PHP, and JavaScript.

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

You can comment on this post by replying to this tweet.
2670207 liked on 19th January 2020
Mike liked on 18th January 2020
Mayur Shingote retweeted on 17th January 2020
Neil retweeted on 17th January 2020
kd liked on 17th January 2020
Ndirangu Waweru β„’ retweeted on 17th January 2020
Jordan Hall retweeted on 17th January 2020
Mayur Shingote retweeted on 17th January 2020
Jordan Hall liked on 17th January 2020
George Drakakis πŸ–– liked on 17th January 2020
M. Vug liked on 17th January 2020
Niels liked on 16th January 2020
Roberto Gallea liked on 16th January 2020
Salman Zafar liked on 16th January 2020
Maarten Buis liked on 16th January 2020
Andres liked on 16th January 2020
Jonas Pardon liked on 16th January 2020
Vladimir Nikolic retweeted on 16th January 2020
Vladimir Nikolic liked on 16th January 2020
Johannes Pichler liked on 16th January 2020
Anton Kristensen liked on 16th January 2020
Edwin I Arellano liked on 16th January 2020
Filipe liked on 16th January 2020
Sobhan liked on 16th January 2020
Wyatt liked on 16th January 2020
Mathijs Broeks liked on 16th January 2020
Yannick Yayo liked on 16th January 2020
. liked on 16th January 2020
Brian Rizzo liked on 16th January 2020
Ben Sherred liked on 16th January 2020
Mayur Shingote retweeted on 16th January 2020
pxgamer liked on 16th January 2020
JosΓ© Cage liked on 16th January 2020
Tim Spratt liked on 16th January 2020
kronos_I retweeted on 16th January 2020
Heru Hang Tryputra liked on 16th January 2020
Daniel Chavez liked on 16th January 2020
Karolis Ščerbiakas liked on 16th January 2020
Andreas Heigl replied on 16th January 2020
I'm usually adding a `git ci --allow-empty` as first commit to a new repo so I can always go back to the empty state...