Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Last active September 18, 2021 05:40
Show Gist options
  • Save hoangitk/665a5134d66ab4cb946dc09bd336b5c0 to your computer and use it in GitHub Desktop.
Save hoangitk/665a5134d66ab4cb946dc09bd336b5c0 to your computer and use it in GitHub Desktop.
[Git reset remote repo] #git

Re-init

Method 1 - reset, keep history and push --force

git reset --soft HEAD^
git add -A .
git commit -m "rewriting history"
git push --force origin master

Method 2 - init and push --force

  1. Delete the .git directory locally.

  2. Recreate the git repostory:

$ cd (project-directory)
$ git init
$ git commit --allow-empty -m 'Initial commit'
  1. Push to remote server, overwriting. Remember you're going to mess everyone else up doing this … you better be the only client.
$ git remote add origin <url>
$ git push --force --set-upstream origin master

Method 3 - orphan (becarefull inuse)

git checkout --orphan reset
git commit --allow-empty -m "reset"
git branch -D master
git branch -m master
git push -f origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment