Skip to content

Instantly share code, notes, and snippets.

@adeluccar
Created August 8, 2017 22:50
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save adeluccar/d105299f2d5af55e3e96f9b989e7eb48 to your computer and use it in GitHub Desktop.
Save adeluccar/d105299f2d5af55e3e96f9b989e7eb48 to your computer and use it in GitHub Desktop.
How to Flatten the History of a Git Repository Safely
git checkout --orphan future-master
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master
git push -f origin master  # Force push master branch to github
git gc --aggressive --prune=all     # remove the old files

Works well with git submodules too. From: https://stackoverflow.com/a/13102849/1253966

@bjoernf73
Copy link

bjoernf73 commented Mar 29, 2021

Does not work - you cannot delete the default branch 'master' - maybe that is some later security measure? Would be great to see an update of this:)

NB! Using gitlab.com though - that may also be a factor...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment