Skip to content

Instantly share code, notes, and snippets.

@khoatran
Last active May 20, 2016 08:52
Show Gist options
  • Save khoatran/3da16902b428e390a76565fd3b8c474e to your computer and use it in GitHub Desktop.
Save khoatran/3da16902b428e390a76565fd3b8c474e to your computer and use it in GitHub Desktop.
Move a git repository to a new one - keep all history. manual.txt for the case you want to do manually. gitmove.sh is a Linux Bash that help you do faster
#!/bin/bash
echo "Please enter the source repository you want to move"
read SOURCE_REPOS
echo "Please enter the target repsitory that you want to move the repos"
read TARGET_REPOS
git clone --bare $SOURCE_REPOS
SOURCE_GIT_META_DIR=$(basename $SOURCE_REPOS)
cd $SOURCE_GIT_META_DIR && git push --mirror $TARGET_REPOS && cd .. && rm -rf $SOURCE_GIT_META_DIR
git clone --bare git@github.com:{USERNAME}/{REPOSITORY_NAME}.git
cd {REPOSITORY_NAME}.git
git push --mirror git@myhost.com:my-new-repo.git
cd ..
rm -rf {REPOSITORY_NAME}.git
Now you have to change remote URL
git remote set-url origin git@myhost.com:my-new-repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment