Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save T12z/b6bde764a55d9e8277b0c36543072f93 to your computer and use it in GitHub Desktop.
Save T12z/b6bde764a55d9e8277b0c36543072f93 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

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