【发布时间】:2020-12-11 17:22:24
【问题描述】:
这是一个与我发现的现有问答不类似的问题。它与我正在遵循的 git 工作流程密切相关,即
- 我在默认的master分支里做git更新,这样我就可以时不时做
git pull。 - 我的更新被推送到 PR 的远程分支。
现在的情况是我需要快速修复,需要从服务器上的 real 主服务器创建一个 git 分支,而不是我本地更改的主服务器 。但是按照我在互联网上找到的建议,我无法做到这一点。
我现在的状态:
. . .
On branch master
Your branch is ahead of 'origin/master' by 52 commits.
. . .
$ git checkout master
Already on 'master'
Your branch is ahead of 'origin/master' by 52 commits.
git checkout -b new-feature
Branch 'new-feature' set up to track local branch 'master' by rebasing.
Switched to a new branch 'new-feature'
$ git status
On branch new-feature
Your branch is up to date with 'master'.
问题是这样的"up-date with 'master'" 是我本地更改的主控,而不是服务器上的真正主控,因为它正在跟踪“本地分支 'master' ",但我希望它以 "origin/master" 为基础并改为跟踪。
【问题讨论】:
-
如果你想更新你本地的
master,那么git pull。如果您不想这样做,那么您可以git fetch,然后在不同的本地分支名称下查看origin/master。 -
@matt,我想并且需要用“git pull”更新我的本地主机。在这种特定情况下,如何查看不同分支名称下的 origin/master?
-
你在说两件相反的事情。如果你想并且需要
git pull,那么git pull。现在您将不再领先于origin/master。我只是不明白这里的问题是什么。 -
简单地说,如果我已经领先于 origin/master,有没有办法从 origin/master 创建分支(并跟踪它)而不是我的本地分支'master'@matt?
-
这能回答你的问题吗? How do I check out a remote Git branch?
标签: git git-branch