Able to push to all git remotes with the one command?

前端 未结 6 1492
广开言路
广开言路 2020-11-30 16:10

Instead of doing:

git push origin --all && git push nodester --all && git push duostack --all

Is there a way to do that wit

6条回答
  •  北海茫月
    2020-11-30 16:33

    If you want to always push to repo1, repo2, and repo3 but always pull only from repo1, set up the remote 'origin' as

    [remote "origin"]
        url = https://exampleuser@example.com/path/to/repo1
        pushurl = https://exampleuser@example.com/path/to/repo1
        pushurl = https://exampleuser@example.com/path/to/repo2
        pushurl = https://exampleuser@example.com/path/to/repo3
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    Configure at command line:

    $ git remote add origin https://exampleuser@example.com/path/to/repo1
    $ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo1
    $ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo2
    $ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo3
    

    If you only want to pull from repo1 but push to repo1 and repo2 for a specific branch specialBranch:

    [remote "origin"]
        url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        ...
    [remote "specialRemote"]
        url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
        pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
        pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo2.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        ...
    [branch "specialBranch"]
        remote = origin
        pushRemote = specialRemote
        ...
    

    See https://git-scm.com/docs/git-config#git-config-branchltnamegtremote.

提交回复
热议问题