Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
script for migrating a git repo between services
# put this function in some file that will be loaded into your bash profile
# I personally use a dedicated sourced file for functions but it could also be placed
# in your .bashrc, .profile, or .bash_profile
# Usage:
# at a bash prompt, run
# migrate-repo <repo-url>
# the repo url could look like
function migrate-repo() {
NAME=new_repo_`date +%s`
if [ -z $1 ]; then
echo "You must provide a target url for the repo"
# this loop grabs all the branches from the (old) remote
# it uses sed to prune the list of branches, which may cause
# issues for some users with nonstandard sed installs (such as mac)
for remote in `git branch -r|sed 's,origin/\|->\|HEAD,,g'`;
git checkout -b $remote
git remote add $NAME $new_repo_url
git push -u $NAME --all
git push -u $NAME --tags
git remote rm origin
git push $NAME master
git remote rename $NAME origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment