30 Apr-2015

Push git to multiple repositories simultaneously

All developers that use GIT as a way for version controlling should know how essential is it sometimes to push your commits to different remote repositories. whether for backing up or to submit your work to different destinations.

In this post, I will be explaining how to push your GIT repository to multiple remotes simultaneously with one git push command.

First, edit your local .git/config file to the following entry, make sure you use your URLs instead:

[remote "all"]
    # add URLs for all the GIT repositories you want to push to.
    url = git@example.com:myRepo.git
    url = git@github.com:myRepo.git
    url = git@anotherBackUp.com:myRepo.git

Once finished, and when you want to push your repository to the previously selected remotes, issue the following command:

git push all –all –dry-run -v

Note that this will push all local branches to all remotes mentioned earlier. you may want to use the following command to push only the working directory:

git push all --dry-run -v

$ git push all --all --dry-run -v< Pushing to git@example.com:myRepo.git
 To git@example.com:myRepo.git
  * [new branch]      datetime_massage_exp -&gt; datetime_massage_exp
  * [new branch]      jquery_attempt -&gt; jquery_attempt
 Pushing to git@github.com:myRepo.git
 To git@github.com:myRepo.git
  * [new branch]      datetime_massage_exp -&gt; datetime_massage_exp<
  * [new branch]      development -&gt; development
  * [new branch]      jquery_attempt -&gt; jquery_attempt