Skip to content

Instantly share code, notes, and snippets.

@fagci
Last active April 3, 2021 13:07
Show Gist options
  • Save fagci/167b25438425c3b82124d9e8e61e8f6a to your computer and use it in GitHub Desktop.
Save fagci/167b25438425c3b82124d9e8e61e8f6a to your computer and use it in GitHub Desktop.
Truncate git history to last state on remote repository (alternative variant)
#!/usr/bin/env sh
# backup repo config
cp .git/config /tmp/truncate.git.config
# cleanup history
rm -rf .git
git init
# restore repo config
mv /tmp/truncate.git.config .git/config
# optional step
git branch -m main
# make first commit
git add .
git commit -m 'initial'
# truncate history on remote repo
git push --force
@fagci
Copy link
Author

fagci commented Apr 3, 2021

Made this as alternative to common approach.
This method preserves repository config.
One thing is to deal with branch name.

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