有人推了一个分行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)
当前回答
对我们来说,似乎remote.origin.fetch
配置存在一个问题。 因此, 我们无法看到比master
, 如此git fetch [--all]
没有帮助,也没有帮助。git checkout mybranch
英git checkout -b mybranch --track origin/mybranch
确实工作过,虽然肯定在遥远的地方。
仅允许上一个配置master
要获取的 :
$ git config --list | grep fetch
remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master
通过使用来修补它*
从源头获取新信息 :
$ git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
$ git fetch
...
* [new branch] ...
...
现在我们可以git checkout
本地边远分支。
我不知道这个配置怎么会 出现在我们本地的仓库里
其他回答
有许多替代办法,例如:
备选案文1:
git fetch && git checkout test
这是最简单的办法
备选案文2:
git fetch
git checkout test
是一样的,但分两步走
TL; DR TR; TL; TDR
使用git switch
而不是git checkout
。更多详情见此页面上的.
我认为答案是过时的。checkout
至switch
和restore
现在。
以下是我的总结:
如果您想要为远程分支更新一些内容, 您应该创建一个本地分支以“ 跟踪” 远程分支 。 您可以在本地更新任何您想要更新的内容, 并最终推到远程 。 如果您在克隆您的仓库后直接检查到远程分支, 您可能会看到“ 忽略的 HEAD” 状态, 以及 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 <remote branch name>
或git switch <remote branch name>
。如果您有一个文件或文件夹的名称与您的远程分支名称相同,git checkout
将输出一些错误消息, 但是git switch
可以正常工作! 正常工作! 正常工作!
示例:
查看所有分支, 我们想要创建一个本地分支, 跟踪远程分支remotes/origin/asd
,我们也有文件名asd
:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/asd
remotes/origin/ereres
remotes/origin/master
remotes/origin/zxc
$ ls
a asd
文件名与远程分支相同, 如果我们使用 Git , Git 应该输出一些错误信息git checkout
创建本地分支以跟踪远程分支
$ git checkout asd
fatal: 'asd' could be both a local file and a tracking branch.
Please use -- (and optionally --no-guess) to disambiguate
如果我们用它,它就会有效git switch
!
$ git switch ereres
Branch 'ereres' set up to track remote branch 'ereres' from 'origin'.
Switched to a new branch 'ereres'
$ git branch -vv
* ereres 3895036 [origin/ereres] Update a
master f9e24a9 [origin/master] Merge branch 'master' of
工作命令
git fetch origin 'remote_branch':'local_branch_name'
git switch 'local_branch_name'
git pull origin 'remote_branch':'local_branch_name'
第一个是从远程分支获取分支和创建本地分支。
第二个是转换到当地分行。
第三是将最近的远距离变化推到当地分部。
要克隆 Git 仓库, 需要 :
git clone <either ssh url /http url>
上述命令检查了所有分支,但只检查了master
将初始化分支。 如果您想要检查其它分支, 请做 :
git checkout -t origin/future_branch (for example)
此命令检查远程分支, 您的本地分支名称将与远程分支相同 。
如果您想要在检查退出时覆盖您的本地分支名称 :
git checkout -t -b enhancement origin/future_branch
现在您的本地分支名称是enhancement
,但您的远程分支名称是future_branch
.
主题说明:与现代基特()1.6.6),您可以使用
git checkout test
(请注意“测试”不是“原产/测试”)DWIM DEWIM DEWIM DEWIM DEWIM DEWIM DEWIM DEWIM DEWIM DEWIM DIWIM DEWIM DIWIM DIWWM DI DIWIM DI DIWIM DI DIWIM DI DIWM DIWIM DI DIWM DI DI DIWIM DI DI DIWM-为您创建本地的“测试”分支, 上游是远程跟踪分支“ 源/ 测试 ” 。
缩略* (no branch)
内git branch
输出是指您在未命名的分支上, 即所谓的“ 列列 HEAD ” 状态( HEAD 指点直接承诺, 而不是某些本地分支的象征性引用) 。 如果您在这个未命名的分支上做了一些承诺, 您总是可以在当前承诺中创建本地分支 :
git checkout -b test HEAD
评论意见中建议的一种更现代的方法:
@Dennis:
git checkout <non-branch>
,例如,git checkout origin/test
产生独立的总部领导/未命名分支,而git checkout test
或git checkout -b test origin/test
地方分支的成果test
(与远程跟踪处一起)origin/test
计为上游上游- 贾库布·纳拉斯基14日8: 17
重点强调git checkout origin/test