简体   繁体   中英

How to set a git branch to push to a remote with a different branch name and pull from completely different url

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM