gpt4 book ai didi

Git checkout 远程仓库的远程分支

转载 作者:太空狗 更新时间:2023-10-29 13:46:09 39 4
gpt4 key购买 nike

当 git clone 一些存储库然后它从中检索所有分支:

git clone https://github.com/android/platform_build.git build1
cd build1/ && git branch -a && cd ..

然后,当我使用 build1 作为镜像并克隆它时,我看不到它的所有远程分支(我只看到 build1 的本地 master 分支)

git clone build1 build2
cd build2 && git branch -a && cd ..

如何远程检查远程分支?

我知道我可以使用命令检查 build1 镜像中的所有远程分支

cd build1 && for remote in `git branch -r `; do git branch --track $remote; done

Track all remote git branches as local branches但是,如果我无权访问 build1 目录怎么办?

此外,还有 git ls-remote origin 命令可以显示所有远程引用,但是有什么优雅的方法可以检查远程分支的远程分支吗?

最佳答案

克隆后build1build2 , build1build2origin , 和 build2https://github.com/android/platform_build.git一无所知,这是“远程”分支所在的地方。一种解决方案可能是添加 https://github.com/android/platform_build.gitbuild2 的配置中作为 Remote .添加一个名为 github 的 Remote :

git remote add github https://github.com/android/platform_build.git

然后运行 ​​fetch获取远程分支:

git fetch github

现在,当你运行 git branch -a你应该看到以 remotes/github/ 为前缀的分支与前缀为 remotes/origin 的那些相对应在 build1 .

另一方面,build2 build1 中的每个本地分支应该有一个远程分支,包括那些正在跟踪来自 build1 的远程分支的分支的视角。例如,如果有一个名为 foo 的分支在 github 上,它将显示为 remotes/origin/foobuild1 .如果您设置本地分支以跟踪 build1 中的远程分支也称为 foo , 然后 build2应该有一个 remotes/origin/foo以及。然后,当foobuild1 中更新通过从 github 的 foo 获取/merge 更改,这些更改应显示在 build2 中在fetch之后/pull .

关于Git checkout 远程仓库的远程分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10581217/

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