Skip to content

Instantly share code, notes, and snippets.

@stash
Last active December 28, 2015 19:19
Show Gist options
  • Select an option

  • Save stash/7549624 to your computer and use it in GitHub Desktop.

Select an option

Save stash/7549624 to your computer and use it in GitHub Desktop.
Rebasing onto a new initial commit
git checkout master
git checkout -b rebaser
git checkout master
git update-ref -d refs/heads/master
git rm -rf $EVERYTHING_EXCEPT_GITIGNORE # figuratively
git commit -m 'initial commit'
# this will remove the commits off of the remote (to be GC'd at some indeterminate point)
git push --force origin master
# now, rebase onto this new, sparse, initial commit
git checkout rebaser
git rebase master # use -i to reword the formerly-initial commit
# assuming you want to make a PR
git push -u origin rebaser
# then, if you want to bring it all back
git checkout master
git reset --hard rebaser
git push --force origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment