【问题标题】:Git track a remote branch and push to a different branchGit 跟踪远程分支并推送到不同的分支
【发布时间】:2018-02-12 23:29:14
【问题描述】:

我有一个本地功能分支 f_branch1,它跟踪远程分支 develop。一天结束时,我将本地分支推送到远程,从而创建了一个新的远程分支f_branch1。 第二天,我从远程 develop 分支更新了我的本地分支,以确保我拥有最新的代码。现在,在这一天结束时,当我尝试将更改推送到前一天创建的远程分支时,我收到了这个错误

error: failed to push some refs to 'remote url.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这是有道理的,但是我怎样才能避免这个错误呢?

编辑

我的意思是,因为我用develop更新了我的本地分支,所以我的本地f_branch1的尖端在其远程f_branch1之前,这就是我收到此错误的原因。我想要的只是在功能分支中确保我的远程工作安全,但同时,让我的工作代码从公共分支develop 更新。

【问题讨论】:

  • 为什么你认为它有意义?看起来你已经破坏了本地分支,请仔细查看提交树。
  • 你本地f_branch1导致的错误信息在后面。并且可以通过显示git log --oneline --decorate --graph --all 的输出来添加分支结构吗? BTW,如果你需要分别在两个不同的分支上工作,你最好使用两个本地分支分别跟踪origin/f_branch1origin/develop
  • 你的问题解决了吗?
  • @Marina-MSFT 好吧,我现在所做的就是用一个远程分支跟踪我的本地功能分支,并定期将远程功能分支与本地分支合并,以便我可以推回我的本地功能分支到这个远程功能分支。希望我能解释一下:)

标签: git github version-control bitbucket


【解决方案1】:

你是如何用 develop 更新你的分支 f_branch1 的?对于这种情况,您应该重新设置分支 f_branch1

 git checkout f_branch1
 git rebase develop

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-04
    • 2016-02-22
    • 2011-01-09
    • 2020-09-26
    • 2011-09-10
    • 2016-07-08
    • 2020-05-22
    • 2010-10-05
    相关资源
    最近更新 更多