Step by step on how to checkout all branches of a remote origin and push them all onto a new origin.
cd
into your reposave the following script under your repo’s path:
123456for branch in `git branch -a | grep remotes/origin`; do# echo ${branch:15:${#branch}}# echo "origin/"${branch:15:${#branch}}git branch --track ${branch:15:${#branch}} "origin/"${branch:15:${#branch}}doneBe sure to comment out the echos to see the prints on terminal before executing the real track command!! All they did was to sub and concat strings return by the
git branch
command. You may have to change the starting and ending indexes, or modify the prefix on target origin branch.It will track all the remote branches to your machine in the following format:
origin branch name:
remotes/origin/develop
local branch name:
develop
command execute:
1git branch --track develop origin/developunder repo path, run
1git fetch --allto update all branches to the latest on your machine.
If you have GUI apps like
SourceTree
on your machine, check and see whether all the branches are latest. If there are still badges telling you there are new commits to pull, pull them before you go on to the next step.create new origin :
1git remote add <new-origin-name> <new-origin-repo-url>example:
1git remote add my-awesome-new-origin http://new-origin-host.com/new-repo.gitpush all local branches to new origin:
1git push --all my-awesome-new-originAll done!
References:
[1] git clone all remote branches locally
[2] How to fetch all git branches
[3] Push local Git repo to new remote including all branches and tags