Search code examples
gitgit-branchgit-pushgit-remote

Git push branch from one remote to another?


I have the following remotes set up:

$ git remote 
korg
rorg

And the following branches:

$ git branch -a
* (no branch)
  remotes/korg/gingerbread
  remotes/korg/gingerbread-release
  remotes/korg/honeycomb
  remotes/korg/honeycomb-mr1-release
  remotes/korg/master
  remotes/m/android-2.3.3_r1 -> refs/tags/android-2.3.3_r1a
  remotes/m/gingerbread -> korg/gingerbread

Now I wish to push all the remote branches from korg to the rorg remote. How do I do that?

Preferably without making a local branch for each first, if that is avoidable.


Solution

  • A quick test making some temporary repositories shows you can construct a refspec that can do this:

    $ git push rorg origin/one:refs/heads/one
    Counting objects: 5, done.
    Writing objects: 100% (3/3), 240 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    To /tmp/rorg
     * [new branch]      origin/one -> one
    

    So origin/BRANCHNAME:refs/heads/BRANCHNAME

    Checking in my rorg remote:

    pat@host /tmp/rorg (BARE:master)
    $ git graph --all
    * 5750bca (HEAD, master) c
    | * 13fd55a (one) b
    |/
    * 822e0de a