tags:
- git
permalink: how-to-replace-remote-git
title: How to replace remote Git repo
date created: Monday, October 7th 2024, 9:38:31 am
date modified: Sunday, May 4th 2025, 10:03:37 am
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 main
after pushing.