gpt4 book ai didi

使用深度 1 选项克隆时 git checkout 新的远程分支

转载 作者:太空狗 更新时间:2023-10-29 13:35:57 25 4
gpt4 key购买 nike

在我克隆了一个 repo 之后,一个新的分支 test 被添加到 origin 远程。但我仍然看到:

$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

我应该使用什么 git 命令来获得以下输出:

$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/test

git checkout remote branch问题不是我的问题,因为这是在我看到所有远程分支引用之后发生的。

我无法再次克隆存储库,因为我在其中进行了本地更改/提交。

那么,如何使用 git 命令将新的远程分支引用引入我的存储库?

我正在使用具有以下分支的 BitBucket 存储库:branches


试验

git fetch 不工作:

$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
$ git fetch
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
$ git fetch origin
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

最佳答案

一个简单的git fetch应该足够了。

这会将 origin/test 带入您的仓库。

然后 git checkout -b test origin/test 将在本地声明该分支。


OP Gabriel Petrovay确认 ( in the comments ) 问题的根源:

There is a slight change in the git config file.

  • In the newly cloned repo [remote "origin"] has fetch = +refs/heads/*:refs/remotes/origin/*
  • but the old repo has fetch = +refs/heads/master:refs/remotes/origin/master.

I kind of feel this is the issue.

确实如此。

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

这应该可以解决。

关于使用深度 1 选项克隆时 git checkout 新的远程分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23387057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com