Git push to multiple remotes asynchronously

If you use something like Dokku or Heroku or any git hook type deploy setup, sometimes you git deploys can become time consuming, especially if you have to do them to multiple servers/remotes. Heres a quick tip to solve that since I had a hard time finding a async solution.

To add multiple urls to a git remote add them to your .git/config manually or run:


git config --add remote.<NAME>.pushurl git@<GIT_REMOTE>
git config --add remote.<NAME>.pushurl git@<GIT_REMOTE>

Now doing

git push NAME master

runs through each remote url individually and does a push. To do this asynchronously simply add this command to your shell profile (.bashrc, .zshrc, .profile, etc):

gpasync () { while read -r url; do git push "$url" "$2" &; done < <(git config --get-all "remote.$1.pushurl"); }

Source the shell profile and from here on out if you do:

gpasync production master

A git push process gets launched for each url and the pushes happen asynchronously.

Also read...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>