有没有办法允许只将指定的本地分支推送到指定的远程?

时间:2021-05-06 16:24:23

description

Here are 2 remotes, origin and foobar.

这里有2个遥控器,起源和foobar。

  • origin has two branches, master and xxxxx
  • origin有两个分支,master和xxxxx
  • foobar has only one branch master
  • foob​​ar只有一个分支大师

origin is my main remote and I have local branches same as origin,
so there are master and xxxxx.

origin是我的主要遥控器,我有与原点相同的本地分支,所以有master和xxxxx。

Sometimes I need to push xxxxx to foobar/master (not foobar/xxxxx),
by putting a command git push foobar xxxxx:master.

有时我需要通过输入命令git push foobar xxxxx:master将xxxxx推送到foobar / master(而不是foobar / xxxxx)。

But I'm afraid to push master to foobar/master by mistake.

但是我害怕错误地将主人推向foobar / master。

So the issue is

Is there any way to prevent the master to push foobar?
Or, is there any way to allow only xxxxx to push to foobar?

有没有办法阻止大师推动foobar?或者,有没有办法只允许xxxxx推送到foobar?

Branches which belong to origin are possiblly to be incleased, and I don't want to push any other branches to foobar but only xxxxx is needed to be pushed as master to foobar.

属于原产地的分支可能会被发布,我不想将任何其他分支推向foobar,但只需要将xxxxx作为主人推送到foobar。

2 个解决方案

#1


2  

Likely you need to set up explicit push mapping in the configuration:

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

git config remote.foobar.push refs/heads/xxxxx:refs/heads/master

and then use git push foobar without explicit branch specification.

然后使用git push foobar而不使用显式分支规范。

Additionally you may set up pre-push hook which would validate commits being pushed.

此外,您可以设置预推钩,以验证正在推送的提交。

#2


0  

By default, git push will sync local branch with that remote branch which local branch is tracking.

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

if you checkout local branch by git checkout --track -b foobar_master foobar/master, when you run git push, foobar_master branch will be synchronized with foobar/master.

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

Please google "remote-tracking branch" for more details.

请谷歌“远程跟踪分支”了解更多详情。

By the way, you can run git branch -vv to confirm which remote branch your local branch is tracking.

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

#1


2  

Likely you need to set up explicit push mapping in the configuration:

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

git config remote.foobar.push refs/heads/xxxxx:refs/heads/master

and then use git push foobar without explicit branch specification.

然后使用git push foobar而不使用显式分支规范。

Additionally you may set up pre-push hook which would validate commits being pushed.

此外,您可以设置预推钩,以验证正在推送的提交。

#2


0  

By default, git push will sync local branch with that remote branch which local branch is tracking.

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

if you checkout local branch by git checkout --track -b foobar_master foobar/master, when you run git push, foobar_master branch will be synchronized with foobar/master.

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

Please google "remote-tracking branch" for more details.

请谷歌“远程跟踪分支”了解更多详情。

By the way, you can run git branch -vv to confirm which remote branch your local branch is tracking.

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