Skip to content

Instantly share code, notes, and snippets.

@michael-sumner
Last active June 9, 2026 13:10
Show Gist options
  • Select an option

  • Save michael-sumner/4d28d7183bbefc41c2e1ff888e85ea03 to your computer and use it in GitHub Desktop.

Select an option

Save michael-sumner/4d28d7183bbefc41c2e1ff888e85ea03 to your computer and use it in GitHub Desktop.
Moving Git repository content to another repository preserving history

Ref: https://stackoverflow.com/questions/17371150/moving-git-repository-content-to-another-repository-preserving-history

Perfectly described here https://www.smashingmagazine.com/2014/05/moving-git-repository-new-server/

First, we have to fetch all of the remote branches and tags from the existing repository to our local index:

git fetch origin

We can check for any missing branches that we need to create a local copy of:

git branch -a

Let’s use the SSH-cloned URL of our new repository to create a new remote in our existing local repository:

git remote add new-origin git@github.com:manakor/manascope.git

Now we are ready to push all local branches and tags to the new remote named new-origin:

git push --all new-origin 
git push --tags new-origin

Let’s make new-origin the default remote:

git remote rm origin

Rename new-origin to just origin, so that it becomes the default remote:

git remote rename new-origin origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment