How to replace remote Git repo

Danger

Make sure you want to completely replace your remote before proceeding.

Create an orphan branch and force push it to overwrite the main branch. This is a destructive operation that creates a new history without any connection to the previous commits.

Create a new orphan branch with no connection to previous history.

git checkout --orphan new_main

Add all current files and commit as usual.

Delete the original main branch.

git branch -D main

Rename your current branch to main.

git branch -m main

Unprotect main in GitHub, then force push local main (or another branch) to it.

git push origin main -f
Re-protect

Re-protect main after pushing.

How to replace remote Git repo
Interactive graph