Skip to content

Instantly share code, notes, and snippets.

@dreammonkey
Created January 29, 2020 13:28
Show Gist options
  • Save dreammonkey/7983e0fd212c09e3d11f40bb7d3b12bc to your computer and use it in GitHub Desktop.
Save dreammonkey/7983e0fd212c09e3d11f40bb7d3b12bc to your computer and use it in GitHub Desktop.
git: backup master branch and start form empty master
; clone the repo
git clone <repository>
; make sure HEAD is master (optional)
git checkout master
; make a local backup of master branch
git branch -m master master_backup
; push local backup branch to server
git push -u origin master_backup
; checkout master using --orphan
git checkout --orphan master
; do a hard reset (removes all files)
git reset --hard
; create a readme (for initial commit)
touch README.md
; make changes and commit
git add .
git commit -m 'Initial commit'
; push new master to server using force
git push origin master --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment