2

我有一个分支,它从一个遥控器拉出并推送到另一个遥控器,U 用于git branch --set-upstream-to=xxxx xxxx设置拉取仓库并git config remote.origin.pushurl user@user.com:repo.git设置推送仓库。

尽管 pull 来自master源 repo 上的分支,但它push会转到upstream目标 repo 上的分支。

当我切换到分支并执行 a 时,git push我会收到通常的--global push.default消息:

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

有没有办法为特定分支指定它应该推送到远程的哪个分支,而不是push.default值,并且类似地用于拉取?

4

1 回答 1

1

这个想法是推送到与分支名称不同的任意命名的分支

只需指定一个上游分支

git branch --set-upstream-to my_local_branch origin/my_remote_branch

然后后续推送将知道要推送到哪个分支my_local_branch

您仍然需要设置推送策略 ( git config push.default simple)

要推送到一个 repo,但从另一个 repo 中提取,您可以将 pushurl 设置为与 pull/fetch url 不同

git config remote.origin.pushurl /url/for/origin/repo
git config remote.origin.url /url/for/upstream/repo

这将允许使用“一个”远程管理所有内容(实际上引用了两个不同的存储库)

您还可以更新上游分支部分的 refspecs:

git config remote.origin.push refs/heads/my_local_branch:refs/heads/my_remote_branch
git config remote.origin.fetch refs/heads/my_local_branch:refs/heads/my_local_branch
于 2015-03-18T07:51:36.567 回答