【问题标题】:How to set a git branch to push to a remote with a different branch name and pull from completely different url如何设置 git 分支以推送到具有不同分支名称的远程并从完全不同的 url 中提取
【发布时间】:2012-10-09 09:20:43
【问题描述】:

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

类似: 从 Server1 上的 PullOnlyRepo 中提取所有内容(我们可能会称其为来源?) 在 Server2 上使用分支名称 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 做到这一点而不必添加额外的东西?

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

【问题讨论】:

  • 您使用的是哪个版本?有很多配置变量...

标签: git git-branch git-remote


【解决方案1】:

您可以为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 jistanidiotreports 取得了相同的结果:

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

【讨论】:

  • 在 git 分支上 --set-upstream hotfix review/JistChanges 我收到一个错误:错误:push.default 的值格式错误:审查错误:必须是无、匹配、跟踪或当前之一。致命:.git/config 中的错误配置文件第 19 行
  • @Jistanidiot 您可以将其设置为 matchingupstream (stackoverflow.com/q/12294787/6309)。
【解决方案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 other where other same origin repo。

【讨论】:

    猜你喜欢
    • 2018-02-12
    • 2020-05-22
    • 1970-01-01
    • 2011-08-09
    • 2015-04-02
    • 1970-01-01
    • 2016-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多