Git – push to multiple remotes

Once upon a time, there comes a need to push to multiple remotes.
This time.. it’s because of Jacek Laskowski.
Specifically, this tweet:

And well, let’s see.

[00:48][ags@ags-mbpro:~/temp/git_for_jacek]
$ git init repo1 --bare
Initialized empty Git repository in /Users/ags/temp/git_for_jacek/repo1/
$ git init repo2 --bare
Initialized empty Git repository in /Users/ags/temp/git_for_jacek/repo2/
$ git init repo_base
Initialized empty Git repository in /Users/ags/temp/git_for_jacek/repo_base/.git/
$ cd repo_base/
[00:48][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ git remote add dla_jacka file:///Users/ags/temp/git_for_jacek/repo1
$ git remote help
error: Unknown subcommand: help
usage: git remote [-v | --verbose]
   or: git remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror=<fetch|push>] <name> <url>
   or: git remote set-url [--push] <name> <newurl> [<oldurl>]
   or: git remote set-url --add <name> <newurl>
   or: git remote set-url --delete <name> <url>
[00:49][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ git remote show dla_jacka 
* remote dla_jacka
  Fetch URL: file:///Users/ags/temp/git_for_jacek/repo1
  Push  URL: file:///Users/ags/temp/git_for_jacek/repo1
  HEAD branch: (unknown)
[00:50][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ git remote set-url dla_jacka --push --add file:///Users/ags/temp/git_for_jacek/repo2
$ git remote -v show
dla_jacka	file:///Users/ags/temp/git_for_jacek/repo1 (fetch)
dla_jacka	file:///Users/ags/temp/git_for_jacek/repo2 (push)

Not exactly right, again.

[00:51][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ git remote set-url dla_jacka --push --add file:///Users/ags/temp/git_for_jacek/repo1
[00:52][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ git remote -v show
dla_jacka	file:///Users/ags/temp/git_for_jacek/repo1 (fetch)
dla_jacka	file:///Users/ags/temp/git_for_jacek/repo2 (push)
dla_jacka	file:///Users/ags/temp/git_for_jacek/repo1 (push)

Hmm, seems like it’s what I need. Let’s try!

[00:52][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ touch test
[00:52][ags@ags-mbpro:~/temp/git_for_jacek/repo_base]
$ git add test
$ git commit -m "first commit, to check things"
[master (root-commit) 39d428d] first commit, to check things
 0 files changed
 create mode 100644 test

Empty file ready, let’s push!

[00:52][ags@ags-mbpro:~/temp/git_for_jacek/repo_base(master)]
$ git push dla_jacka master
Counting objects: 3, done.
Writing objects: 100% (3/3), 224 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To file:///Users/ags/temp/git_for_jacek/repo2
 * [new branch]      master -> master
Counting objects: 3, done.
Writing objects: 100% (3/3), 224 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To file:///Users/ags/temp/git_for_jacek/repo1
 * [new branch]      master -> master

Bang, works 🙂

Author: ags

bio

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.