2

I have a branch which pulls from one remote and pushes to another and U used git branch --set-upstream-to=xxxx xxxx to set the pull repo and git config remote.origin.pushurl [email protected]:repo.git to set the push repo.

Although the pull is from the master branch on the source repo, the push goes to the upstream branch on the destination repo.

When I switch to the branch and I do a git push I get the usual --global push.default message:

warning: push.default is unset; its implicit value has changed in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the traditional behavior, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple When push.default is set to 'matching', git will push local branches to the remote branches that already exist with the same name. 

Is there a way to specify for a particular branch which branch of the remote it should push to, rather than the push.default value, and similarly for pulls as well?

4
  • do you mean to push to a same name branch in a different repository? Commented Mar 18, 2015 at 5:37
  • see stackoverflow.com/questions/25964577/… Commented Mar 18, 2015 at 5:45
  • @AndrewC No. the idea is to push to any arbitrarily named branch that is different from the branch name Commented Mar 18, 2015 at 7:44
  • Isn't that what the answer covered? Commented Mar 18, 2015 at 16:55

1 Answer 1

1

the idea is to push to any arbitrarily named branch that is different from the branch name

Simply specify an upstream branch:

git branch --set-upstream-to my_local_branch origin/my_remote_branch 

Then subsequent pushes will know to which branch to push my_local_branch.

You would still need to setup a push policy (git config push.default simple)

To push to one repo, but pull from another, you can setup the pushurl to be different from the pull/fetch url

git config remote.origin.pushurl /url/for/origin/repo git config remote.origin.url /url/for/upstream/repo 

That would allow to manage everything with "one" remote (which actually references two different repos)

You can also update the refspecs for the upstream branch part:

git config remote.origin.push refs/heads/my_local_branch:refs/heads/my_remote_branch git config remote.origin.fetch refs/heads/my_local_branch:refs/heads/my_local_branch 
Sign up to request clarification or add additional context in comments.

8 Comments

I haven't really played with this yet, just reading the manpages. You still have to provide the local branch name for either matching or simple, don't you (meaning a ref-less git push will not suffice)?
The repo that is pulled from is not the same repo that is pushed to. --set-upstream-to specifies the branch pulled from, and the branch names are different. The pull is from master on the source repo, but upstream on the destination repo. The upstream repo is never pushed to. I wanted to edit the comment but it timed out
Your latest answer with the remote.origin.pushurl setting is what I was inquiring about. Does that configuration syntax allow one to specify the branch as well, ie git config remote.origin.pushurl /url/for/origin/repo/<branch>, in order for git push to work even if the --global push.default has not been set?
@vfclists the branch is set by the push refspec, not the push url. See git-scm.com/docs/git-push#REMOTES, and longair.net/blog/2011/02/27/…: “refspecs” are usually of the form <src>:<dst>, telling you which local branch (src) you’d like to update the remote branch (def) with. However, the default behaviour if you don’t add :<dst>, as in this example, is explained as If :<dst> is omitted, the same ref as <src> will be updated.
In my instance the branch pulls from master branch in the source repo and pushes to the upstream branch in the destination. Would that result in some like this: ` [remote "upstream"]` ` url = github.com/sourceuser/repo.git` ` fetch = +refs/heads/*:refs/remotes/upstream/*` ` tagopt = --tags` ` pushurl = github.com/destuser/repo.git` ` push = +refs/heads/upstream:refs/remotes/upstream`
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.