根据分支将 git 拉和推到不同的默认远程
Having git pull and push to different default remotes based on the branch
我想弄清楚如何设置 git 我可以 pull/push from/to 一个遥控器,默认情况下 pulls/pushes 它进入它自己的本地分支。
这个遥控器不会是原始遥控器,我想偶尔将分支合并到主分支,这将是 pushed/pulled to/from 原始。
但重要的是要注意其他遥控器将完全独立并拥有自己的主控和此类分支。所以它可能看起来像这样
remote-a (master) -> local (remote-a-branch)
任何帮助将不胜感激,在此先感谢
使用这个
git remote add remote_name https://github.com/...
git checkout -b tracks_remote_name
git config brangh.tracks_remote_name.remote remote_name
- 您可以拥有任意数量的遥控器。请注意所有遥控器都是平等的 -
origin
在任何意义上都不是特殊的遥控器。它只是 第一个默认远程 你在克隆新的 repo 之后。您可以使用 git remote
命令 (reference) 管理它们
git remote add remote123 <REMOTE_URL>
- 您可以拥有任意数量的分支。您可以设置本地分支来跟踪单个远程分支。
git checkout
帮助您做到这一点。 (reference). git branch
can do this too using --set-upstream-to
key (reference)
示例:
# create branch, checkout to newly created branch and setup tracking
git checkout -b remote123_master remote123/master
这将设置本地分支 remote123_master
以跟踪来自远程 remote123
的 master
分支。
据我了解您的需求,您将拥有以下工作流程:
git checkout master // switch to default master (tracked from origin/master)
git pull // if needed from origin
git push // if needed to origin
// do the job, commit
git checkout remote123_master // switch to master from other remote
git pull // if needed from remote123
git push // if needed to remote123
// do the job, commit
git checkout master // go back to master
git merge remote123_master // merge master from remote123 to master
git push // if needed to origin
更新
如果您不打算提交到其他远程服务器,您可以跳过为 remote123
创建本地分支的步骤。然后它看起来像:
git remote add remote123 <REMOTE_URL>
git fetch remote123 // fetch data from remote but do not modify local branches
git checkout master // switch to default master (tracked from origin/master)
git pull // if needed from origin
git push // if needed to origin
// do the job, commit
git fetch remote123 // fetch data from remote but do not modify local branches
git merge remote123/master // merge directly with remote branch reference without creating local one
git push // if needed to origin
我想弄清楚如何设置 git 我可以 pull/push from/to 一个遥控器,默认情况下 pulls/pushes 它进入它自己的本地分支。
这个遥控器不会是原始遥控器,我想偶尔将分支合并到主分支,这将是 pushed/pulled to/from 原始。
但重要的是要注意其他遥控器将完全独立并拥有自己的主控和此类分支。所以它可能看起来像这样
remote-a (master) -> local (remote-a-branch)
任何帮助将不胜感激,在此先感谢
使用这个
git remote add remote_name https://github.com/...
git checkout -b tracks_remote_name
git config brangh.tracks_remote_name.remote remote_name
- 您可以拥有任意数量的遥控器。请注意所有遥控器都是平等的 -
origin
在任何意义上都不是特殊的遥控器。它只是 第一个默认远程 你在克隆新的 repo 之后。您可以使用git remote
命令 (reference) 管理它们
git remote add remote123 <REMOTE_URL>
- 您可以拥有任意数量的分支。您可以设置本地分支来跟踪单个远程分支。
git checkout
帮助您做到这一点。 (reference).git branch
can do this too using--set-upstream-to
key (reference)
示例:
# create branch, checkout to newly created branch and setup tracking
git checkout -b remote123_master remote123/master
这将设置本地分支 remote123_master
以跟踪来自远程 remote123
的 master
分支。
据我了解您的需求,您将拥有以下工作流程:
git checkout master // switch to default master (tracked from origin/master)
git pull // if needed from origin
git push // if needed to origin
// do the job, commit
git checkout remote123_master // switch to master from other remote
git pull // if needed from remote123
git push // if needed to remote123
// do the job, commit
git checkout master // go back to master
git merge remote123_master // merge master from remote123 to master
git push // if needed to origin
更新
如果您不打算提交到其他远程服务器,您可以跳过为 remote123
创建本地分支的步骤。然后它看起来像:
git remote add remote123 <REMOTE_URL>
git fetch remote123 // fetch data from remote but do not modify local branches
git checkout master // switch to default master (tracked from origin/master)
git pull // if needed from origin
git push // if needed to origin
// do the job, commit
git fetch remote123 // fetch data from remote but do not modify local branches
git merge remote123/master // merge directly with remote branch reference without creating local one
git push // if needed to origin