【问题标题】:Git checkout remote branch deleted locally本地删除git checkout远程分支
【发布时间】:2021-08-22 18:11:35
【问题描述】:

在我的一个系统中,我在处理一个项目时进行了更改并推送了它。现在我有了一个具有所有相同 ssh/用户详细信息的新系统,我克隆了该项目并希望通过检查我的分支来继续我未完成的更改。在这里我犯了一个错误:我使用 -b 选项进行了结帐,即

git checkout -b mybranch
//instead of 
git checkout mybranch

所以向我展示了一个空白分支,而不是克隆的远程分支。

所以我使用以下方法删除了本地创建的分支:

git branch -d mybranch

我尝试了以下事情(通过谷歌搜索)但没有成功:

git checkout --track origin/mybranch
git pull origin origin/mybranch

如何拉取并结帐到 mybranch?

【问题讨论】:

  • 删除后,你应该可以git checkout mybranch,就像你自己说的那样
  • 您可以删除并再次克隆项目作为解决方法

标签: git git-branch git-checkout git-remote


【解决方案1】:

如果周围没有工作,让分支看起来像是从远程分支开始的。

# dangerous, that's why i said _if_ there's no work laying around
git reset --hard origin/mybranch # place the local branch where the remote branch is (local branch and worktree content)
git branch --set-upstream origin/mybranch

应该够了。

但是鉴于您已经删除了本地分支

git checkout mybranch

应该足以让 git 从远程创建本地分支

【讨论】:

    【解决方案2】:

    步骤:

    1. 请同事切换到 myBranch。
    2. 将我的 project/.git/config 文件的内容替换为他的同一文件的内容。
    3. 结帐 myBranch。有效!

    当命令没有帮助时,这个技巧对我有用。 ?

    【讨论】:

      猜你喜欢
      • 2016-07-08
      • 2011-01-01
      相关资源
      最近更新 更多