如何设置一个git分支以推送到具有不同分支名称的远程并从完全不同的URL拉出

时间:2012-10-18 20:00:29

标签: git git-branch git-remote

我的本​​地git repo需要从一台服务器上拉。然后,它需要将特定分支推送到具有不同服务器上的不同分支名称的审阅存储库。

像: 从Server1上的PullOnlyRepo中提取所有内容(我们可能会调用该来源吗?) 在Branch2上使用分支名称JistChanges将分支修补程序推送到ReivewRepo。

现在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执行我想要的操作(从Server1上的正确位置获取更改并将它们合并到我的工作树中)。

然而git push没有。为了实现我想做的事情

git push review hotfix:JistChanges

有没有办法让git pull做到这一点,而不必添加额外的东西?

有一些问题已经设置好,以便您的本地分支推送到具有不同分支名称的远程。然而,它们也改变了上游和拉动的来源。

2 个答案:

答案 0 :(得分:4)

您可以为hotfix设置upstream分支:

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

请参阅“How do you make an existing git branch track a remote branch?” 请参阅默认push政策中的“What is the result of git push origin?”(即将成为“simple”)

启动git1.8.0:

git branch -u review/JistChanges hotfix

OP jistanidiot reports取得了相同的结果:

git remote set-url --push origin
git config remote.origin.push refs/heads/hotfix:JistChanges

答案 1 :(得分:2)

Ok VonC的回答让我走上正轨。这是我做的:

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

唯一的问题是现在所有东西都推向了评论报道。现在没关系,因为90%的工作都在这个分支中。另外10%我可以用其他相同的原始仓库以正确的推送配置执行git push。