【问题标题】:git - Pushing a local branch to the remote tracking branch of a parentgit - 将本地分支推送到父级的远程跟踪分支
【发布时间】:2016-02-22 22:25:45
【问题描述】:

我的沙盒存储库中有一个名为local-branch 的本地分支,它跟踪一个名为remote-branch 的远程分支。我因此创建了本地分支:

$ git checkout -b local-branch remotes/origin/remote-branch

我从local-branch 创建了一个名为dev-branch 的分支:

$ git checkout -b dev-branch local-branch

然后我向dev-branch 提交了一些更改,现在想将其推送到remote-branch 的一个分支。在那里,它得到审查、批准,然后合并到remote-branch。之后,我需要在我的local-branchgit pull 以将其与remote-branch 同步。

我正在尝试以下方法,但这似乎不起作用。

$ git push remotes/origin/remote-branch local-branch

我看到以下错误:

fatal: 'remotes/origin/remote-branch' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

但我在运行时可以看到存储库:

$ git branch -a

【问题讨论】:

  • 看起来像:$ git push origin local-branch 有效。

标签: git github version-control git-branch git-push


【解决方案1】:

要将local-branch 从存储库推送到远程origin 上的remote-branch,请使用

git push origin local-branch:remote-branch

根据您在问题中创建local-branch 的方式,git 应该已将其配置为跟踪origin/remote-branch。在这种情况下,一个简单的git pull 同时签出local-branch 就足以同步。

您的工作流程很复杂。我建议寻找简化每个给定分支的名称的方法。

【讨论】:

  • 整个local-branch 是多余的,因为它似乎没有用作工作分支。只需从 remote-branch 指向的地方创建 dev-branch 就足够了。然后只需 git push origin dev-branch 完成工作分支即可。我猜对 Git 中分支的含义存在一些误解:分支不引用其他分支,只引用提交,而提交又链接到它们的父提交。父母与孩子之间没有联系。这将需要在新提交上重写最新提交。这就是“悬空提交”不好的原因。
猜你喜欢
  • 2014-02-04
  • 1970-01-01
  • 2018-02-12
  • 1970-01-01
  • 2016-10-25
  • 2013-04-30
  • 2010-09-27
  • 2011-01-09
  • 2019-02-16
相关资源
最近更新 更多