Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save valera-rozuvan/eb2c86131b23cf8e9d366d685c910fc6 to your computer and use it in GitHub Desktop.
Save valera-rozuvan/eb2c86131b23cf8e9d366d685c910fc6 to your computer and use it in GitHub Desktop.
git switch to new remote and remove old remote

git switch to new remote and remove old remote

The following assumptions are made:

  • you are on branch main
  • your local working tree is clean
  • you have the remote origin currently in place
  • you want to switch to a new remote mirror_github
  • you want to get rid of your old remote origin

Here is what needs to be done:

git remote add mirror_github github:user/repo.git
git fetch --prune mirror_github
git reset --hard mirror_github/main
git clean -f -d
git switch -C main mirror_github/main
git remote remove origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment