Last active
February 15, 2023 18:08
-
-
Save jotajr/2fe26ea9b019bb6b8a8efb14ff51acfd to your computer and use it in GitHub Desktop.
[GIT] Migrate a git repository to a new one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Moving a repo by Jota Jr | |
echo "Script to migrate a repository to a new origin" | |
echo "Enter the git repository path: " | |
read path_repo | |
echo "Enter new-origin git url:" | |
read new_git_origin | |
echo "Repo path: $path_repo" | |
cd $path_repo | |
echo "New Origin URL: $new_git_origin" | |
echo "Fetching All" | |
git fetch --all | |
echo "Pull All" | |
git pull --all | |
echo "Checkout all branches" | |
git branch -r | grep -v '\->' | while read remote; do git checkout "${remote#origin/}"; done | |
echo "Adding new remote repository" | |
git remote add new-origin $new_git_origin | |
echo "Pushing all to new origin" | |
git push --all new-origin | |
echo "Pushing all tags to new origin" | |
git push --tags new-origin | |
echo "Show all remotes:" | |
git remote -v | |
echo "Removing initial origin" | |
git remote rm origin | |
echo "Renaming new origin to origin" | |
git remote rename new-origin origin | |
echo "New origin:" | |
git remote -v | |
echo "==== Everything is done!!! ====" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment