7

My local git repo needs to pull from one server. It then needs to push a specific branch to a review repo with a different branch name on a different server.

Something like: Pull everything from PullOnlyRepo on Server1 (we'll call that origin maybe?) Push Branch hotfix to ReivewRepo with branch name JistChanges on Server2.

Right now git config -l shows:

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=<URL for Server1>
remote.origin.pushurl=no_push (this shouldn't matter since it is a pull only repo)
branch.production.remote=origin
branch.production.merge=refs/heads/production
remote.review.url=<URL for Server2>
remote.review.fetch=+refs/heads/*:refs/remotes/review/*

git pull does what I want (fetch changes from the correct place on Server1 and merges them into my work tree).

However git push doesn't. In order to achieve what I want I have to do

git push review hotfix:JistChanges

Is there some way to make git pull do this without having to put in the extra stuff?

There are some questions out there already that set up so that your local branch pushes to a remote with a different branch name. However they also change the upstream and where the pull comes from.

Martin Ellis
  • 9,603
  • 42
  • 53
Jistanidiot
  • 54,334
  • 4
  • 18
  • 29

2 Answers2

4

You could set the upstream branch for hotfix:

git config push.default upstream
git config push.default review 
git branch --set-upstream hotfix review/JistChanges

See "How do you make an existing git branch track a remote branch?" See "What is the result of git push origin?" on the default push policy (soon to be "simple")

Starting git1.8.0:

git branch -u review/JistChanges hotfix

The OP jistanidiot reports having achieved the same result with:

git remote set-url --push origin
git config remote.origin.push refs/heads/hotfix:JistChanges
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • On the git branch --set-upstream hotfix review/JistChanges I get an error: error: Malformed value for push.default: review error: Must be one of nothing, matching, tracking or current. fatal: bad config file line 19 in .git/config – Jistanidiot Oct 19 '12 at 12:14
  • @Jistanidiot you could set it to `matching` or `upstream` (http://stackoverflow.com/q/12294787/6309). – VonC Oct 19 '12 at 15:08
3

Ok VonC's answer got me on the right track. Here's what I did:

git remote set-url --push origin <review repo URL>
git config remote.origin.push refs/heads/hotfix:JistChanges

The only problem with this is that now everything pushes to the review repo. That's ok for now since 90% of the work will be in this branch. The other 10% I can just do a git push other where other the same origin repo with the correct push configuration.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Jistanidiot
  • 54,334
  • 4
  • 18
  • 29