有人将称为 Git 推力源测试的分支推向共享仓库 。 我可以看到有 git 分支 -r 的分支 。 我如何查看远程测试分支 ? 我试过 :
git 检出测试, 它不会给 git 检出源/ 测试提供任何结果 * (无分支)
有人将称为 Git 推力源测试的分支推向共享仓库 。 我可以看到有 git 分支 -r 的分支 。 我如何查看远程测试分支 ? 我试过 :
git 检出测试, 它不会给 git 检出源/ 测试提供任何结果 * (无分支)
当前回答
你基本上看到了分支, 但你还没有本地副本...
您需要获取分支...
您可以简单地获取并退出分支,然后使用下面的一条线命令来做到这一点:
git fetch && git checkout test
我还创建了下面的图像, 供您分享差异, 查看如何取取如何工作, 以及拉动如何不同 :
调
其他回答
您可以尝试
git fetch remote
git checkout --track -b local_branch_name origin/branch_name
或
git fetch
git checkout -b local_branch_name origin/branch_name
使用抓取来拉动全部远程
git fetch --all
列表远程分支 :
git branch -r
列表所有您的分支
git branch -l
>>outpots like-
* develop
test
master
要取出/更改分支
git checkout master
被接受的答案不为你工作?
第一个和选定答案在技术上是正确的,但您可能尚未从远程仓库中检索到所有对象和参考文献。 如果是这样,您将会收到以下错误:
$ git checkout -b remote_branch origin/remote_branch
致命: git 检出: 更新路径与切换分支不兼容 。 您是否打算检查“ 来源/ remote_ branch ” , 无法以承诺方式解决 ?
解决方案
如果您收到此信件, 您必须先从 Git 获取源代码中获取消息, 在运行 git 检查远程_ 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 抓取来源时, 检索到我们尚未设置的远程分支 来追踪本地机器 。 从那里, 既然我们现在有一个 ref 到远程分支, 我们可以简单地运行 git 检查远程支架, 我们会从远程跟踪中受益 。
tl; dr , tl; dr
使用 git 开关而不是 git 检出。 更多详情请见此页面 。
我认为答案已经过时。 git 将一些退票功能分割为切换和现在恢复 。
以下是我的总结:
如果您想要为远程分支更新一些内容, 您应该创建一个本地分支以“ 跟踪” 远程分支。 您可以在本地更新任何您想要更新的内容, 并最终推到远程 。 如果您在克隆您的仓库后直接检查到远程分支, 您可能会看到“ 标记头” 状态, 并从 git 中看到以下信息 :
Note: switching to 'origin/asd'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at d3e1083 Update a
如何建立本地分支跟踪远程分支?
要创建本地分支以跟踪远程分支, 您可以使用 git checkout & lt; remote 分支名 & gt; 或 git 开关 < remote 分支名 & gt; 。 如果您有一个文件或文件夹与您的远程分支名有相同名称, git checkout 会输出一些错误消息, 但是 git 开关通常可以正常工作 。
例如:
查看所有分支, 我们想要创建一个本地分支, 以跟踪远程分支遥控器/ 原发/ ass 。 我们也有一个文件名称 : $ git 分支 - a * 主遥控器/ 原发/ 头发- & gt; 原发/ 主遥控器/原发/ 原发/ 远地/ 原发/ 原发/ 原发/ zxc $ 。 以文件名和文件名相同 。 如果我们使用 Git 检查命令创建本地分支以跟踪远程分支 $ git 检查结果, git 则应该输出一些错误信息 。
您可以开始跟踪所有远程分支, 使用以下制表单脚本 :
#!/bin/bash
git fetch --all
for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`
do git branch -f --track "$branch" "origin/$branch"
done
这里还有一个单行版本 :
git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`; do git branch --track "$branch" "origin/$branch" ; done ;