Last active
October 4, 2017 12:32
-
-
Save jamalnasir/a4746a19919d3b29adf0c387f9c5a662 to your computer and use it in GitHub Desktop.
Clone all branches and tags between remote git repositories
This file contains hidden or 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
# Clone a temporary copy of your repo | |
cd /temp | |
git clone ssh://git@yourrepo/yourrepo.git | |
cd yourrepo | |
function branches() { | |
git branch -r | grep -v '\->'; | |
} | |
BRANCHES=$(branches) | |
# Start tracking all the remote branches locally | |
for branch in $BRANCHES | |
do | |
######### replacing origin/ in the branch name. if you don't need it then skip this block ########## | |
string_to_replace='origin/' | |
replace_with='' | |
branch="${branch/$string_to_replace/$replace_with}" | |
#################################################################################################### | |
git checkout $branch | |
git checkout master | |
echo $branch | |
echo '===================' | |
done | |
# Remove your old origin | |
git remote rm origin | |
# Add your new remote | |
git remote add origin ssh://git@newrepo/yourrepo.git | |
# Now push it up to the new host | |
git push -u --all origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment