Skip to content

Instantly share code, notes, and snippets.

@mohanarpit
Created May 31, 2013 14:21
Show Gist options
  • Save mohanarpit/5685300 to your computer and use it in GitHub Desktop.
Save mohanarpit/5685300 to your computer and use it in GitHub Desktop.
This script migrates the local repository from an old remote origin to a new origin. Handy if you're migrating your repository from one service provider to another.
#!/bin/bash
echo "Input the path of the local repository: "
read localPath
echo "Input the URL of the new remote repo: "
read newRemote
cd $localPath
#Get the current remote repo
oldRemote=git remote -v | awk '{print $2}'
#Mirror the current repo in a local directory
git clone --mirror $oldRemote bare_repo/
#Push the tree to the new repo
git push -f --all $newRemote
#Push the tags to the new repo
git push -f --tags $newRemote
#Update the remote origin in the local repo
git config remote.origin.url $newRemote
rm -rf bare_repo/
cd -
@kapad
Copy link

kapad commented May 31, 2013

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment