Q:

git push all branches from one remote to another remote

I have two remote: upstream and origin. upstream is something I can't push to. origin is my own repo. How can I fetch all branches from upstream and then push them to origin?
I tried:
git fetch upstream
git push --all origin

But it doesn't work.

A:

You may want to try cloning your upstream repo with --mirror option and then push to your new remote with --mirror option too
You'll have the following flow:
git clone <upstream-repo-url/repo.git> --mirror
cd <repo>
git remote add <your-remote-name> <your-remote-url/repo.git>
git push <your-remote-name> --mirror

A:

I just needed to copy one repository from Bitbucket to GitHub, these are the steps assuming your remote is called origin, all branches and tags will be copied:
git remote add neworigin url-to-new-remote
git push neworigin --tags refs/remotes/origin/*:refs/heads/*

Good thing about this is that files in your working copy won't be modified.

A:

One complete answer of cloning from one (bare) repository to another (bare) repository taking ALL branches, not just the checked out ones, is to clone a local bare repository as an intermediary. Then all branches are pulled as part of the clone and a git push --all will push them all. Example performed on Windows from github to gitlab:

git clone --bare git@github.com:robe070/cookbooks.git
cd cookbooks.git
git remote add gitlab git@gitlab.com:robe071/cookbookstest2.git
git push --force --all gitlab
git push --force --tags gitlab

Result: 25 branches pushed to gitlab
Note, git checkout is not required for all the branches and meaningless to a bare repo anyway.

