Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I push to more than one repository in a single command in git?

Basically I wanted to do something like git push mybranch to repo1, repo2, repo3

right now I'm just typing push many times, and if I'm in a hurry to the the pushing done, I just send them all to the background git push repo1 & git push repo2 &

I'm just wondering if git natively supports what I want to do, or if maybe there's a clever script out there, or maybe a way to edit the local repo config file to say a branch should be pushed to multiple remotes.

like image 732
kch Avatar asked Oct 02 '08 23:10

kch


People also ask

How would you go on about pushing the same file to two different projects using git?

Doing git remote -v should reveal the current URLs for each remote. Now, if you want to push to two or more repositories using a single command, you may create a new remote named all (as suggested by @Adam Nelson in comments), or keep using the origin , though the latter name is less descriptive for this purpose.

Is there a way to put multiple projects in a git repository?

Yes. You can put multiple projects in one Git repository but they would need to be on different branches within that repo. The Git console in ReadyAPI gives you the ability to create or switch branches from the UI. More information on the Git integration can be found here in the documentation.


2 Answers

You can have several URLs per remote in git, even though the git remote command did not appear to expose this last I checked. In .git/config, put something like this:

[remote "public"]     url = [email protected]:kch/inheritable_templates.git     url = kch@homeserver:projects/inheritable_templates.git 

Now you can say “git push public” to push to both repos at once.

like image 83
Aristotle Pagaltzis Avatar answered Sep 21 '22 16:09

Aristotle Pagaltzis


What I do is have a single bare repository that lives in my home directory that I push to. The post-update hook in that repository then pushes or rsyncs to several other publicly visible locations.

Here is my hooks/post-update:

#!/bin/sh # # An example hook script to prepare a packed repository for use over # dumb transports. # # To enable this hook, make this file executable by "chmod +x post-update".  # Update static info that will be used by git clients accessing # the git directory over HTTP rather than the git protocol. git-update-server-info  # Copy git repository files to my web server for HTTP serving. rsync -av --delete -e ssh /home/afranco/repositories/public/ [email protected]:/srv/www/htdocs/git/  # Upload to github git-push --mirror github  
like image 35
Adam Franco Avatar answered Sep 22 '22 16:09

Adam Franco