代码之家  ›  专栏  ›  技术社区  ›  Eliseo

不能拉或推

  •  0
  • Eliseo  · 技术社区  · 2 年前

    当我做 git pull 在master分支中,git显示以下消息:

    There is no tracking information for the current branch.
    Please specify which branch you want to merge to.
    See git-pull(1) for details.
    
    git pull <remote> <branch>
    
    If you want to set up the tracing information for this branch, you can do it with:
    git branch --set-upstream-to=origin/<branch> master
    

    当我这样做的时候 git push 在master分支中,git显示以下消息:

    fatal: The current master branch does not have an upstream branch.
    To push the current branch and set the remote as upstream, use
    
    git push --set-upstream origin master
    

    所以我愿意 git push --set-upstream origin master ,git显示此消息:

    To <my-server-name>
    ! [rejected] master -> master (non-fast-forward)
    error: failed to push some references to '<my-server-name>'.
    help: Updates were rejected because the tip of your current branch is
    help: behind its remote counterpart. Integrate remote changes (i.e.
    help: 'git pull ...') before pushing again.
    help: See 'Note about fast-forwards' in 'git push --help' for details.
    

    请帮帮我!

    2 回复  |  直到 2 年前
        1
  •  1
  •   akseli    2 年前

    您首先需要确保本地分支引用上游分支,方法是运行: git branch --set-upstream-to=origin/<branch> master

    之后,你会想要表演 git pull 从上游分支获取丢失的更改。

    一旦您进行了更改,您将能够执行 git push ,但也有可能您必须执行 manual merge 以便解决由于您所做的更改和上游分支中存在的更改而产生的任何冲突。

        2
  •  0
  •   big bob little    2 年前

    首先,您必须指向本地代码库以匹配远程git分支。如果你还没有,可以通过在你的终端中键入这个来实现。代替 '<分支 github/bitbucket等中的分支名称,也称为remote。如果您没有任何远程分支,它将默认为 主/主

    git branch --set-upstream-to=origin/<branch> master
    

    输入此命令后无法推送到master的第二部分

    git push --set-upstream origin master
    

    是因为远程(例如github)发生了更改,而该远程当前不在您的本地计算机上。因此,您必须提取这些更改,以便在返回到远程分支之前,本地分支和远程分支可以是最新的。

    您可以使用以下任意一种方法

    git pull 
    git pull origin master
    

    您可能会看到的另一件事是git提示您应该使用什么策略来进一步将更改从远程机器拉到本地机器。它可能是

    • 合并/重新基准

    根据您的偏好,您必须通过输入命令来设置它,该命令将显示在控制台中的消息中。