Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git proxy that pushes to multiple remotes

Tags:

git

proxy

heroku

I'm looking for a piece of software that I hope someone has built. I'm going to describe this software here hoping that someone heard about something like this and can point me in the right direction.

I'm developing a web app which is deployed on Heroku. Because of Heroku's limitations, I am being put in the unfortunate situation of having four (4) remote Git repos for the same repos.

Why four?

We have multiple "apps" on Heroku. One for production and a couple of staging "apps". These are all for the same actual app, but on Heroku they are separate "apps", so we could try things out on staging before pushing them to production.

Each app on Heroku gets its own separate Git repo, and automatically deploys the master branch every time a new commit is pushed to that master branch. This policy of Heroku is the crux of our problem. Because this means that we have 3 different repos on Heroku, plus our GitHub repo.

Why is it a problem having 4 different Git remotes? Because it means that when you develop and create new commits, you have to either (1) push to only one remote or (2) push to all remotes.

Doing (1) means thinking which remote you'd like to push to. I hate having to think about this. When I develop, I don't care about the remotes, I commit and push and get back to work. If I want to deploy a branch into staging server 1, for example, I would merge that branch into the staging_1 branch and push it. I don't like picking which remote to push to.

Another disadvantage of (1) is that your remotes go out of sync.

What I want is (2). I want every push action to push to all of our four repos.

But there are 2 problems with that:

Problem 1: The staging "apps" on Heroku deploy what's on master. I don't want them to do that. I want to map the staging_1 branch in my repo to the master branch on the staging server Git repo.

Problem 2: Having my computer push to all 4 repos will take a long time. Even 1 Heroku push action takes a long time. It can take 40 seconds sometimes.


Proposed solution

Here's what I want. I want to have a specialized Git server that acts as a proxy. Whenever I push from my local computer into this Git server, it'll push those same branches into our 4 repos in parallel. In that way, from my local computer's perspective, the push will seem instantaneous, while this proxy server will automatically deal with the Heroku repos in the background.

If the push to any of the 4 remotes fails for any reason, I want this proxy to report back in some way so I'll know something is broken and could fix it.

Another thing that this proxy will have to do is the master mapping. Every time I would push the staging_1 branch to it, it'll push it as staging_1 to all the remotes, but to the remote belonging to the staging server it will also push that branch as master, so Heroku will know to deploy it.

(It's pretty sad that Heroku is designed in a way that makes me need a proxy like this, but that's what I have to deal with.)

So that's it. That's the solution I want. Does anyone know of such a program?

like image 968
Ram Rachum Avatar asked Apr 25 '12 11:04

Ram Rachum


People also ask

Can I git push to multiple remotes?

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.

Does git push push to all remotes?

Now all fetch and pull operations will only fetch from your original remote repository. But with a simple git push git pushes your latest changes to all remote repositories you've added right now.

How do I add a second remote to git?

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A unique remote name, for example, “my_awesome_new_remote_repo” A remote URL, which you can find on the Source sub-tab of your Git repo.


1 Answers

Create a new repository, which you can push to when you want the push to propagate, and write a post-receive hook to propagate the changes when you push into this repo.

like image 183
Andrew Aylett Avatar answered Oct 21 '22 12:10

Andrew Aylett