5

I have cloned my repo and would like to push all my remote branches (origin/*) to a new remote which I configured. I have tried:

git push anotherRemote --all

but it only pushes the ones that I made a local copy from. When I type:

git branch -r

I see all the branches located on my other remote (which I have not created local copies of). How to I push those to my anotherRemote ?

u123
  • 15,603
  • 58
  • 186
  • 303

2 Answers2

8

Simply specify explicitly what you want to push where:

git push anotherRemote refs/remotes/origin/*:refs/heads/*

This will take all remote branches of origin and push them as normal branches on the other remote. (Verify with git fetch anotherRemote; git branch -rv.)

Beware of the --mirror option unless you really understand what it does!

michas
  • 25,361
  • 15
  • 76
  • 121
0

Use the --mirror option to git push. From the documentation:

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.

See also How to make a GitHub mirror to Bitbucket?.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Here they warn against using --mirror. https://answers.atlassian.com/questions/54235/importing-an-existing-repository-into-stash – u123 Feb 15 '14 at 16:19
  • @u123, that appears to warn against using `--mirror` with `git clone`. I'm suggesting to use it with `git push`. – ChrisGPT was on strike Feb 15 '14 at 16:22
  • 1
    hm git push anotherRemote --mirror does not have any effect. I still do not see the remote branches on my anotherRemote – u123 Feb 15 '14 at 18:43