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

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

当前回答

如果该分支所在的事物上不是其他的,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 fetch --all
git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>

等于

 git fetch --all

时和时

 git checkout -b fixes_for_dev origin/development

两者将创造latest fixes_for_dev调自development

TL; DR TR; TL; TDR

使用git switch而不是git checkout。更多详情见此页面上的.

我认为答案是过时的。checkoutswitchrestore现在。

以下是我的总结:

如果您想要为远程分支更新一些内容, 您应该创建一个本地分支以“ 跟踪” 远程分支 。 您可以在本地更新任何您想要更新的内容, 并最终推到远程 。 如果您在克隆您的仓库后直接检查到远程分支, 您可能会看到“ 忽略的 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可以正常工作! 正常工作! 正常工作!

示例:

  1. 查看所有分支, 我们想要创建一个本地分支, 跟踪远程分支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
    
  2. 文件名与远程分支相同, 如果我们使用 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
    
  3. 如果我们用它,它就会有效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 检查退出测试, 无效

Does nothing不等于doesn't work,所以我猜想当您在终端键入“ Gitt 检出测试” 并按键输入密钥时,没有出现消息,也没有出错。对不对?

如果答案是"是" 我可以告诉你原因

原因是在您的工作树上有一个名为“ 测试” 的文件( 或文件夹) 。

何时git checkout xxx被弃绝,

  1. 吉特看着xxx一开始是树枝名称, 但没有任何树枝名称测试 。
  2. 然后基特觉得xxx这是一条道路,幸运的是,有一个名为“测试”的文件。git checkout xxx表示丢弃任何修改xxx文件。
  3. 如果没有名字的文件xxx或,然后 Git 将尝试创建xxx根据某些规则,其中一项规则是设立一个部门,名为:xxx如果remotes/origin/xxx存在。

我尝试了上面的解决方案,但行不通。试试这个,它奏效了:

git fetch origin 'remote_branch':'local_branch_name'

这将获取远程分支, 并创建一个新本地分支( 如果尚未存在) 名称local_branch_name并追踪其中的遥控者。

出于某种原因,我不能做:

git checkout -b branch-name origin/branch-name

它在抛出错误:

致命 : “ 来源/ 分支名称” 不是一个承诺, 无法从中创建分支“ 分支名称 ” 。

我必须这样做:

git checkout -b branch-name commit-sha