In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch. As an example, let's say that you have created a local branch named “my-feature”.
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
To push the all branches to a remote git, we can use the git push command followed by the --all flag and origin.
It is easy to synchronize code between multiple git repositories, especially, pushing to multiple remotes. This is helpful when you're maintaining mirrors / copies of the same repository. All you need to do is set up multiple push URLs on a remote and then perform git push to that remote as you usually do.
I've found this one:
git push rorg 'refs/remotes/korg/*:refs/heads/*'
And it pushed all my remote branches from korg to rorg (even without local copies of the branches). See the output below:
Counting objects: 293, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (67/67), done.
Writing objects: 100% (176/176), 48.32 KiB, done.
Total 176 (delta 105), reused 168 (delta 97)
remote: Resolving deltas: 11% (12/105)
To <<MY_REPOSITORY_URL>>
* [new branch] korg/gingerbread-> gingerbread
* [new branch] korg/gingerbread-release -> gingerbread-release
* [new branch] korg/honeycomb-> honeycomb
* [new branch] korg/HEAD -> HEAD
* [new branch] korg/honeycomb-mr1-release-> honeycomb-mr1-release
* [new branch] korg/master -> master
And then you can make the same push for tags
refs:
git push rorg 'refs/tags/*:refs/tags/*'
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
To complement patthoyt's answer, here's a short shell script that pushes all the branches from one remote to another:
SRC_REMOTE=korg
DST_REMOTE=rorg
for a in $(git branch --list --remote "$SRC_REMOTE/*" | grep -v --regexp='->')
do git push "$DST_REMOTE" "$a:refs/heads/${a//$SRC_REMOTE\/}"
done
To summarize, for each remote branch on the source remote (excluding "pointer" branches like HEAD), push that ref to the destination remote. (The ${a//$SRC_REMOTE\/}
bit strips the source remote name from the branch name, i.e., origin/master
becomes master
.)
This works in Zsh
Notice the single quote is necessary to prevent unexpected parameter expansion in some cases.
git push rorg 'refs/remotes/korg/*:refs/heads/*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With