1

This answer explains how to push to multiple repos simultaneously.

  1. My .git/config contains:

    [remote "all"]
        url = git@github.com:commerce-sciences/scale-master.git
        url = git@heroku.ron:scale-master.git
    
  2. git push all successfully deploys to heroku.

  3. It seems that changes are not pushed to github for some reason.

> git push all
Everything up-to-date
Everything up-to-date

> git status
# On branch master
# Your branch is ahead of 'origin/master' by 22 commits.
#
nothing to commit (working directory clean)

What am I missing?

Community
  • 1
  • 1
ripper234
  • 222,824
  • 274
  • 634
  • 905
  • Can you confirm that the GitHub really didn’t update? I.e. via the website, or by running `git fetch origin`? – poke Mar 07 '13 at 14:03

3 Answers3

5

The way you have configured your all remote repository, it’s not linked to the existing repositories in your local repository at all. So the second repository in all is not the same as origin although it has the same URL.

When you push to all, Git does not know that it also pushes to origin while doing that. As such it can’t update the remote branches that are in your local repository.

Unfortunately, you cannot change this behaviour. git push does not support remote repository groups as git fetch does. At least not yet. If it did, Git would have an explicit link from the remote repository (group) all to origin and could update the local references.

So for now, the only option you have is to fetch the individual remotes right after pushing to all, using git fetch origin or just git fetch (for remote-tracking branches), or push to them explicitely to begin with.

poke
  • 369,085
  • 72
  • 557
  • 602
2

From what of what I understand of your need, you don't need an "all" remote. : just configure the second push url on the "origin" remote, and you won't have this problem.

[remote "origin"]
    url = git@github.com:commerce-sciences/scale-master.git
    url = git@heroku.ron:scale-master.git

output of git remote -v :

origin git@github.com:commerce-sciences/scale-master.git (fetch)
origin git@github.com:commerce-sciences/scale-master.git (push)
origin git@heroku.ron:scale-master.git (push)

Which means that : - git push origin now pushes to both urls. - git fetch origin (still) only fetches from the first url

Pierre-Olivier Vares
  • 1,687
  • 15
  • 20
1

But if you really want separated "all" and "origin" remotes, you still can do correctly what you want.

The key is (one more time) in the pretty cool configuration of git.

Let's see what happens when you git push all :

  • git pushes on the first url (okay)

  • git pushes on the second url (okay)

  • it then fetches the first url to update the remote branches of your repository, refs/remote/all.

Why does git complains about having "commit in advance" ? Because it compares your current branch (master) with the upstream branch, which is origin/master.

The fact is, we can change (either one will suffice) :

  1. the updated branch, so we fetch all into refs/remotes/origin rather than into refs/remote/all. In the [remote "all"] config block, the line

    fetch = +refs/heads/*:refs/remotes/all/*

means "update refs/remotes/all". So you've just to add/change it to :

`fetch = +refs/heads/*:refs/remotes/origin/*`

And it's done : git fetch originand git fetch all will now have the same effect (update the origin/master branch)

Warning : too much playing with fetch configuration can lead to a repository where you don't know what is really done. So keep it simple and logical.

  1. the remote branch that git compares your current one

If you git push --set-upstream all, then your master branch will follow all/master rather than origin/master. So it won't complain about you having commit. Note that you have to to this only once, as the upstream branch is permanently retained.

In short :

Method 1 : Change fetch configuration for remote "all"

[remote "all"]
   url = (url1)
   url = (url2)
   -fetch = +refs/heads/*:refs/remotes/all/*
   +fetch = +refs/heads/*:refs/remotes/origin/*

Method 2 : make your branch follow all/master rather than origin/master

[branch "master"]
    -remote = origin
    +remote = all
    merge = refs/heads/master
Pierre-Olivier Vares
  • 1,687
  • 15
  • 20