Git - Different Remote for each Branch

后端 未结 1 1722
逝去的感伤
逝去的感伤 2020-12-23 11:30

I\'m unsure of how to ask this properly but I\'ll try and do my best - I\'m by no means a Git aficionado, I know how to use the basic commands but not advanced term

1条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 12:16

    You can set a different branch to push to a different server for individual branches by using these commands:

    As of Git 1.8.0:

    git branch -u origin/foo foo
    

    Note: If the last foo is left out, it will choose the current branch.

    As of Git 1.7.0:

    git branch --set-upstream foo origin/foo
    

    In your case, you would use this by adding your two remotes (mydomain and github) and setting each branch to push to them individually. It might look something like this:

    Make sure you add the remotes if you haven't already:

    git remote add github git://github.com/foo/myrepo.git
    git remote add mydomain git://git.mydomain.com/foo/myrepo.git
    

    Then set the branches to push to the right places:

    git branch -u mydomain/private private
    git branch -u github/public public
    

    After this is all set up, you can push and pull just by using git push and git pull. This will push and pull to github when you're on the public branch, and to your mydomain.com when you're on your private branch.

    0 讨论(0)
提交回复
热议问题