pull/push from multiple remote locations

后端 未结 15 1257
傲寒
傲寒 2020-11-21 10:17

The short: is there a way to have a git repo push to and pull from a list of remote repos (rather than a single \"origin\")?

The long:

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 10:35

    You can configure multiple remote repositories with the git remote command:

    git remote add alt alt-machine:/path/to/repo
    

    To fetch from all the configured remotes and update tracking branches, but not merge into HEAD, do:

    git remote update
    

    If it's not currently connected to one of the remotes, it will take time out or throw an error, and go on to the next. You'll have to manually merge from the fetched repositories, or cherry-pick, depending on how you want to organize collecting changes.

    To fetch the master branch from alt and pull it into your current head, do:

    git pull alt master
    

    So in fact git pull is almost shorthand for git pull origin HEAD (actually it looks in the config file to determine this, but you get the idea).

    For pushing updates, you have to do that to each repo manually.
    A push was, I think, designed with the central-repository workflow in mind.

提交回复
热议问题