macoril
macoril

Reputation: 167

Is there any way to allow to push only specified local branch to specified remote?

description

Here are 2 remotes, origin and foobar.

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

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

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

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?

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.

Upvotes: 1

Views: 80

Answers (2)

user3159253
user3159253

Reputation: 17455

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.

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

Upvotes: 2

gzh
gzh

Reputation: 3616

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

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.

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.

Upvotes: 0

Related Questions