有人推了一个分行test
与git push origin test
共享仓库的共享仓库。git branch -r
如何查看遥控器test
我试过了
git checkout test
,它没有做任何事情git checkout origin/test
给给* (no branch)
有人推了一个分行test
与git push origin test
共享仓库的共享仓库。git branch -r
如何查看遥控器test
我试过了
git checkout test
,它没有做任何事情git checkout origin/test
给给* (no branch)
当前回答
git fetch && git checkout your-branch-name
其他回答
我尝试了上面的解决方案,但行不通。试试这个,它奏效了:
git fetch origin 'remote_branch':'local_branch_name'
这将获取远程分支, 并创建一个新本地分支( 如果尚未存在) 名称local_branch_name
并追踪其中的遥控者。
虽然第一个和选定的答案是技术上的正确中,您可能尚未从远程仓库中检索到所有对象和参考文献。如果是这种情况,您将会收到以下错误:
$ 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 --all
要列出远程分支 :
git branch -r
列出您所有的分支
git branch -l
>>outpots like-
* develop
test
master
要取出/更改分支
git checkout master
工作命令
git fetch origin 'remote_branch':'local_branch_name'
git switch 'local_branch_name'
git pull origin 'remote_branch':'local_branch_name'
第一个是从远程分支获取分支和创建本地分支。
第二个是转换到当地分行。
第三是将最近的远距离变化推到当地分部。
在这种情况下,你可能想要 创建本地test
正在跟踪远程test
分支 :
$ git branch test origin/test
先前版本的git
,你需要一个明确的--track
选项,但当您正在从一个远程分支进行分支分割时,这是默认值。
创建本地分支和切换到它,使用:
$ git checkout -b test origin/test