git checkout新的远程分支时克隆深度1选项 [英] git checkout new remote branch when cloning with depth 1 option
问题描述
在我做了一个repo的克隆之后,一个新的分支 test
已被添加到 origin
remote中。但是我仍然看到:
pre $ code $ git branch -a
$ master
remotes / origin / HEAD - >原产地/主人
遥控器/原产地/主人
我应该使用哪些git命令得到以下输出:
$ p $ $ git branch -a
* master
remotes / origin / HEAD - >原产地/主人
遥控器/原产地/主人
遥控器/原产地/测试
应该足够了。
$ b
这会给您的回购带来原产地/测试。
然后,一个 git checkout -b test origin / test
将在本地声明该分支。
$git配置文件有一点变化。
$ b
- 在新克隆的回购
[remoteorigin]
hasfetch = + refs / heads / *:refs / remotes / origin / *
- 但旧回购有
fetch = +参考文献/头/主:参/遥控器/来源/主
。
我觉得这是问题所在。
确实如此。
git config remote.origin.fetch+ refs / heads / *:refs /遥控器/原产地/ *
这应该可以解决它。
After I did a clone of a repo, a new branch test
has been added to the origin
remote. But I still see:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
What git command/s should I use to get the following output:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/test
The git checkout remote branch question is not my question because that is happening after I see all the remote branch references.
I cannot clone the repo again because I have my local changes/commits in it.
So, how to bring the new remote branch references to my repo using git commands?
I am using a BitBucket repo that has the following branches:
Trials
git fetch
does not work:
$ 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
A simple git fetch
should be enough.
That will bring origin/test to your repo.
Then a git checkout -b test origin/test
will declare that branch locally.
The OP Gabriel Petrovay confirms (in the comments) the source of the problem:
There is a slight change in the git config file.
- In the newly cloned repo
[remote "origin"]
hasfetch = +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.
It is indeed.
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
That should solve it.
这篇关于git checkout新的远程分支时克隆深度1选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!