简体   繁体   English

如何设置git分支以推送到具有不同分支名称的远程并从完全不同的url中提取

[英]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. 我的本地git repo需要从一台服务器中提取。 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. 诸如此类:从Server1上的PullOnlyRepo中提取所有内容(我们可能称其为起源?)将分支修补程序推送至Server2上具有分支名称JistChanges的ReivewRepo。

Right now git config -l shows: 现在,git config -l显示:

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). git pull可以实现我想要的功能(从Server1的正确位置获取更改并将它们合并到我的工作树中)。

However git push doesn't. 但是git push不会。 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? 有什么方法可以使git pull做到这一点而不必放入多余的东西吗?

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 : 您可以为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 ") 请参阅“ 如何使现有的git分支跟踪远程分支? ”请参阅默认push策略上的“ git push origin的结果是什么? ”(很快就会变得“ simple ”)

Starting git1.8.0: 从git1.8.0开始:

git branch -u review/JistChanges hotfix

The OP jistanidiot reports having achieved the same result with: 吉斯坦迪奥特OP 报告取得了相同的结果,其中:

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. Ok VonC的回答使我步入正轨。 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. 现在还可以,因为90%的工作将在此分支中。 The other 10% I can just do a git push other where other the same origin repo with the correct push configuration. 其他10%的人可以使用git push进行其他操作,其中其他人使用正确的push配置进行相同的原始回购。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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