如何设置一个git分支来推送到具有不同分支名称的远程,并从完全不同的url中获取 [英] How to set a git branch to push to a remote with a different branch name and pull from completely different url
问题描述
我的本地git仓库需要从一台服务器上卸载。然后它需要将一个特定的分支推送到一个在不同服务器上使用不同分支名称的评论库。
类似于:
从Server1上的PullOnlyRepo (我们会称这个起源可能?)
将分支修补程序推送到ReivewRepo,并在Server2上使用分支名称JistChanges。
现在git config -l显示:
remote.origin .fetch = + refs / heads / *:refs / remotes / origin / *
remote.origin.url =< URL for Server1>
remote.origin.pushurl = no_push(这应该不重要,因为它只是一个拉回购)
branch.production.remote =原产地
branch.production.merge = refs / heads /制作
remote.review.url =< URL2 for Server2>
remote.review.fetch = + refs / heads / *:refs / remotes / review / *
然而,git push并没有做到我想要的(从Server1上的正确位置获取更改并将它们合并到我的工作树中)。为了实现我想要的功能
git push review hotfix:JistChanges
有没有办法让git pull做到这一点,而不必放入额外的东西?
已经有一些问题已经设置,以便您的本地分支推送到具有不同分支名称的远程。然而他们也改变了上游和拉来自哪里。
您可以设置上游分支为修补程序
:
git config push.default upstream
git config push.default review $ b $ git branch --set-upstream hotfix review / JistChanges
请参阅如何让现有的git分支跟踪远程分支?
请参阅什么是 git push origin
?的结果对于默认的推送
政策(即将成为简单
)
启动git1.8.0:
git branch -u review / JistChanges修补程序
< OP jistanidiot 报告已经取得同样的结果:
git remote set-url --push origin
git config remote.origin.push refs / heads / hotfix:JistChanges
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
这篇关于如何设置一个git分支来推送到具有不同分支名称的远程,并从完全不同的url中获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!