2

I have two remotes, public and private, and two branches, master and learn.

When I'm on master I'd like git push to push to both public and private; and when I'm on learn I'd like git push to push to just private.

I've tried git push --all private -u, but this doesn't seem to have any effect.


In detail, I've done:

$ git remote remove public
$ git remote remove private
$ git remote add public https://github.com/.../A.git
$ git remote add private https://github.com/.../B.git
$ git push -u public master
Branch master set up to track remote branch master from public.
$ git push --all private -u
Branch learn set up to track remote branch learn from private.
Branch master set up to track remote branch master from private.

Running git branch -avv (after manually pushing everything to each branch) gives:

* learn                  6489f4c [private/learn] ...
  master                 6489f4c [private/master] ...
  remotes/private/learn  6489f4c ...
  remotes/private/master 6489f4c ...
  remotes/public/master  6489f4c ...
orome
  • 45,163
  • 57
  • 202
  • 418
  • I don't think it's possible to specify multiple remotes for a single push – Jeff Puckett Aug 19 '16 at 17:55
  • However, you could chain them with a post-receive hook on your public remote that would automatically push master to your private remote. This way you only push master to public, but it's then replicated to private. – Jeff Puckett Aug 19 '16 at 17:58
  • @JeffPuckettII: That might work (especially if it's the only way!). Can you elaborate? – orome Aug 19 '16 at 18:01
  • @JeffPuckettII: Also, FWIW, I mostly work within [Tower](https://www.git-tower.com), so if there's a solution that works there, I'd like that. – orome Aug 19 '16 at 18:02
  • Because you're using Github, [you can't run git hooks](http://stackoverflow.com/q/19041220/4233593), just their API for webhooks. So the simplest thing would probably be to just create an alias for two pushes. – Jeff Puckett Aug 19 '16 at 18:15
  • Put the hook @JeffPuckettII suggests into an embedded shared-objects proxy repo, `git init --bare -s . .git/x-raxa-stuff/pushproxy`, that'll use almost no space, and set branch.master.push. You could even do it in the pre-receive, the objects are available because they're shared. – jthill Oct 01 '16 at 19:32

1 Answers1

0

First add your remote repos info into git

     git remote add origin https://github.com/gitachyut/a.git
     git remote add nonorigin https://github.com/gitachyut/b.git

here origin, nonorigin is the name of the repo alias name

At the time of push, define the repo name just like below

    git push origin master

    git push nonorigin testing

Syntax

    git push {repo alias name } { branch name }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Achyut Kr Deka
  • 739
  • 1
  • 8
  • 18