有人推了一个分行testgit push origin test共享仓库的共享仓库。git branch -r如何查看遥控器test我试过了

  • git checkout test,它没有做任何事情
  • git checkout origin/test给给* (no branch)

当前回答

我用了那个:

git clean -fxd                         # removes untracked (new added plus ignored files)

git fetch
git checkout {branchname}

git reset --hard origin/{branchname}   # removes staged and working directory changes

其他回答

如果该分支所在的事物上不是其他的,origin我喜欢做以下工作:

$ git fetch
$ git checkout -b second/next upstream/next

这将检出next分支上upstream远程连接到一个本地分支,该分支被调用second/next。这意味着,如果您已经拥有下一个命名为本地分支的分支,则不会发生冲突。

$ git branch -a
* second/next
  remotes/origin/next
  remotes/upstream/next

这些答案对我毫无用处。

git checkout -b feature/branch remotes/origin/feature/branch

接受接受的答复不为你工作?

虽然第一个和选定的答案是技术上的正确中,您可能尚未从远程仓库中检索到所有对象和参考文献。如果是这种情况,您将会收到以下错误:

$ git checkout -b remote_branch origin/remote_branch

致命: git 检出: 更新路径与切换分支不兼容 。
您是否打算检查“ 来源/ remote_ branch ” 无法以承诺方式解决的“ 来源/ 远程- branch ” ?

解决方案

如果您收到此消息, 您必须首先完成git fetch origin何 地origin是运行前的远程仓库的名称git checkout remote_branch。以下是答复的完整例子:

$ git fetch origin
remote: Counting objects: 140, done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 69 (delta 36), reused 66 (delta 33)
Unpacking objects: 100% (69/69), done.
From https://github.com/githubuser/repo-name
   e6ef1e0..5029161  develop    -> origin/develop
 * [new branch]      demo       -> origin/demo
   d80f8d7..359eab0  master     -> origin/master

$ git checkout demo
Branch demo set up to track remote branch demo from origin.
Switched to a new branch 'demo'

如你所见 跑着跑着git fetch origin检索到我们尚未安装的远程分支, 以跟踪本地机器 。 从那里, 因为我们现在有一个 ref 到远程分支, 我们就可以运行git checkout remote_branch我们会从远程追踪中受益

你基本上看到了树枝,但你还没有本地的拷贝!

你需要,你需要fetch分支...

您可以简单地获取并退出分支, 使用下面的一条线命令来做到这一点 :

git fetch && git checkout test

我还创建了下面的图像 让你分享差异,看看如何fetch以及它是如何与pull:

git fetch

git branch -r表示对象名称无效, 因为该分支名称不在 Git 的本地分支列表中。 更新您的本地分支列表来源 :

git remote update

然后再试着检查一下你的远程分支

这对我管用

我相信git fetch拉拉进全部( 全部)远端树枝,这不是最初的海报所要的。