2

According to the git-config documentation for branch.<name>.merge:

branch.<name>.merge

Defines, together with branch.<name>.remote, the upstream branch for the given branch. It tells git fetch/git pull/git rebase which branch to merge and can also affect git push (see push.default).

Is there an equivalent setting to specify the upstream branch to push to, for the given branch? This is the behaviour I want to achieve - say I have a branch A with remote set to origin. On running git push from branch A, the result should be equivalent to running git push refs/heads/A:refs/for/master.

Alternatively, is there a value of remote.*.push which will achieve this behaviour? Setting remote.origin.push to refs/heads/*:refs/for/master resulted in an invalid refspec.

Pradhan
  • 16,391
  • 3
  • 44
  • 59
  • "say I have a branch A with remote set to origin" I am unfamiliar with any ability for a branch to have a remote repo. I am interpreting from this that your repository has an remote defined for a branch on your upstream repo called "origin". On the other hand, I think what you are saying is that you have cloned an upstream repo, and your only remote defined locally is called "origin" and points to upstream master. – ThatsAMorais Apr 16 '15 at 06:34
  • @ThatsAMorais I am not sure why that statement is ambiguous. But perhaps this will phrase it better. I have a `remote` named `origin` defined. My local repository has a branch named `A`. Also, `git config branch.A.remote` outputs `origin`. – Pradhan Apr 16 '15 at 06:38
  • Ah, thanks! That is clearer. – ThatsAMorais Apr 16 '15 at 06:42

1 Answers1

0

I think that this post may be helpful: git alias for HEAD:refs/for/master

Community
  • 1
  • 1
ThatsAMorais
  • 659
  • 8
  • 16
  • No, that isn't what I am asking. BTW, the answer you linked to is what you will find if you dig into the doc quote from my question "can also affect git push (see push.default)". When `push.default` is set to `upstream`, `branch..merge` is the remote branch that `git-push` uses with no refspec specified. – Pradhan Apr 16 '15 at 06:44
  • Okay, maybe more clarification is required. I did not restate your question well, but I believe you are trying to avoid having to specify the ref to master each time (e.g. refs/heads/A:refs/for/master) The solution I posted should set the upstream branch name permanently. – ThatsAMorais Apr 16 '15 at 06:55
  • Yes, but the problem is that the refspec I want to push to is `refs/for/master` while the refspec that will get picked based on the upstream branch set to `master` is `refs/heads/master`. There isn't a branch name corresponding to this refspec AFAIK. BTW, as you might already have recognized, `refs/for/master` because gerrit is involved. – Pradhan Apr 16 '15 at 06:58
  • Thanks, but that doesn't work either - that was my first attempt but with that refspec for `remote.origin.push`, `git push` in branch `A` ends up being equivalent to `git push origin refs/heads/A:refs/for/A`. That's how the `remote.*.push` value of `refs/heads/*:refs/for/*` gets interpreted. – Pradhan Apr 16 '15 at 07:19