Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 是否有任何方法允许仅将指定的本地分支推送到指定的远程分支? 描述_Git_Git Branch_Git Push_Git Remote - Fatal编程技术网

Git 是否有任何方法允许仅将指定的本地分支推送到指定的远程分支? 描述

Git 是否有任何方法允许仅将指定的本地分支推送到指定的远程分支? 描述,git,git-branch,git-push,git-remote,Git,Git Branch,Git Push,Git Remote,这里有两个遥控器,origin和foobar origin有两个分支,master和xxxxx foobar只有一个分支master origin是我的主要遥控器,我有与origin相同的本地分支, 所以有master和xxxxx 有时我需要将xxxxx推送到foobar/master(不是foobar/xxxxx), 通过放置一个命令git push foobar xxxxx:master 但我害怕错误地把师父推给foobar/师父 所以问题是 有什么方法可以防止主机推foobar? 或者

这里有两个遥控器,
origin
foobar

  • origin有两个分支,
    master
    xxxxx
  • foobar只有一个分支
    master
origin是我的主要遥控器,我有与origin相同的本地分支,
所以有
master
xxxxx

有时我需要将xxxxx推送到foobar/master(不是foobar/xxxxx),
通过放置一个命令
git push foobar xxxxx:master

但我害怕错误地把师父推给foobar/师父

所以问题是 有什么方法可以防止主机推foobar?
或者,有没有办法只允许xxxxx推送到foobar


属于origin的分支可能会被包含,我不想将任何其他分支推送到foobar,但只需要将xxxxx作为主分支推送到foobar。

默认情况下,
git push
将本地分支与本地分支跟踪的远程分支同步

如果您通过
git checkout--track-b foobar\u master foobar/master
签出本地分支,当您运行
git push
时,foobar\u master分支将与foobar/master同步

请谷歌“远程跟踪分支”了解更多详细信息


顺便说一下,您可以运行
git branch-vv
来确认本地分支正在跟踪哪个远程分支。

您可能需要在配置中设置显式推送映射:

git config remote.foobar.push refs/heads/xxxxx:refs/heads/master
然后在没有显式分支规范的情况下使用git push foobar


此外,您可以设置钩子来验证推送的提交。

我不需要跟踪
foobar/master
。我需要推送到
foobar/master
的分支是
xxxxx
,该分支跟踪
origin/xxxxx
。但我不知道-vv选项,它会帮助我。谢谢你提供的信息。这样看起来不错!:为了安全起见,我试着准备了预推钩,以严格禁止,这并不困难,而且效果很好。但是为了避免错误,配置看起来已经足够了。谢谢啊,只有一件事
git-config远程foobar-refs/heads/xxxxx:refs/heads/master
未成功。所以我把这个命令改为
git-config-remote.foobar.push-refs/heads/xxxxx:refs/heads/master
。我的git版本是2.9.0。