简体   繁体   中英

Is there a way to push to more than one remote Git branch at the same time?

In my local repo's .git/config I have

[remote "public"]
        url = https://github.com/rax/somerepo.git
        fetch = +refs/heads/*:refs/remotes/public/*
[branch "master"]
        remote = public
        merge = refs/heads/master
[remote "amazon"]
        url = ssh://ubuntu@ecXXXXXXXXX.us-west-2.compute.amazonaws.com/home/ubuntu/somebarerepo.git
        fetch = +refs/heads/*:refs/remotes/amazon/*
[remote "all"]
        url = https://github.com/rax/somerepo.git
        url = ssh://ubuntu@ecXXXXXXXXX.us-west-2.compute.amazonaws.com/home/ubuntu/somebarerepo.git

and when I git push all I successfully push the latest commit to both the amazon and public remotes; but the remote branches don't track. For example, if public is behind when I push, even though the content there is now up to date, the branch is still indicated as behind.

Is there a way to push to more than one remote branch at the same time?

The short answer is that you can do it.

BUT form git version 2.0 the default behavior has changed so you will have to set the 'push.default' to the desired value (matching in your case)


Here is the git v2.0 release notes which explain the change in the way git treat push (simple vs matching). This was updated in git v2.0 to fix the default git push behavior.

Prior to git v2.0 when you executed git push it would have pushed all your changed branches ( all and not only the current branch).

Git v2.0 Release Notes

Backward compatibility notes

When git push [$there] does not say what to push, we have used the traditional matching semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there). In Git 2.0, the default is now the simple semantics, which pushes:

  • only the current branch to the branch with the same name, and only when the current branch is set to integrate with that remote branch, if you are pushing to the same remote as you fetch from; or

  • only the current branch to the branch with the same name, if you are pushing to a remote that is not where you usually fetch from.

You can use the configuration variable push.default to change this. If you are an old-timer who wants to keep using the matching semantics, you can set the variable to matching , for example. Read the documentation for other possibilities. strong text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM