For any script I sugges you run, it would be wise to stash or commit all your changes.
I needed to push several branches from one remote to another. These answers required that the local branches previously existed
SRC_R=origin1
DEST_R=origin2
for cbranch in $(git branch -r | grep $SRC_R | cut -d '/' -f2,3,4,5 | cut -d ' ' -f1)
do
git checkout $cbranch
git push $DEST_R $cbranch
done
Just change origin1 to the source remote, and origin2 to the destination remote.
Copy this into "remoteBranchCloner.sh" and call it using "sh callBranchCloner.sh".
There may be a better way, that doesn't do several pushes.
If you use my code you probably want to use credential caching, otherwise you have to type your credentials serveral times.
For windows:
Note: This script is for linux. If you run it in "git bash" the script will work, but you can't run it from the native console without having installed something special.
git config [--global] credential.helper wincred
For linux
git config [--global] credential.helper cache
Where [--global] means optionally add --global
If you would like to set remote tracking for all branches to a new remote:
DEST_R=remotename
for cbranch in `git branch`
do
git checkout $cbranch
git branch -u guru/$cbranch
done
Stored as a .sh file and ran with "sh filename.sh" will set all upstreams to track remote 'remotename'