git - 如何将 git 远程分支引用带到本地

标签 git branch git-branch

创建一个新的 git 分支:

git checkout -b test

并将其推送到原点:

git push origin -u 测试

并列出我现在得到的所有分支:

  master
* test
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/test

现在,我想在另一台机器上执行一个命令来获取远程分支引用。我该怎么做?

我想要输出:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/test

并且该命令不知道新分支的名称。

我尝试过:git pullgit pull --allgit fetchgit fetch --all。还有什么?

编辑:我需要一个命令告诉我:

* [new branch]      test       -> origin/test

如果不先 checkout 分支,这可能吗?我也不想删除我的存储库并再次克隆它。

最佳答案

on another machine I want execute a command to get the remote branch refs.

您可以启动一个空的 repo,添加一个源并执行 ls-remote(如完成 in the comments of your other question ):

git init newRepo
cd newRepo
git remote add origin /url/remote/repo
git ls-remote origin

这允许您查看远程仓库的分支,而无需在本地克隆/获取任何内容。
由于您在一个空的存储库中,因此您可以决定要获取的内容。


作为jthill提及 in the comments , git ls-remote部分不需要从 git 存储库运行。
例如,考虑:

cd / # to illustrate that you can be anywhere
git ls-remote git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git 'refs/heads/*'

如果您已经有一个克隆的 repo,并且不介意下载 delta,那么 git fetch 应该可以工作,前提是它的 refspec 设置为获取所有分支。
(同样,如您的其他问题“git checkout new remote branch when cloning with depth 1 option ”所示)

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

关于git - 如何将 git 远程分支引用带到本地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18592397/

相关文章:

git - 如何 Git 忽略这些文件

git - Jenkins Git 插件和 Refspecs

Git:管理分支

git - 当我还没有准备好提交时,如何在 git 分支中隔离我的更改?

git - 使用 Git 为多个客户端管理来自 master 分支的多个分支

git - 什么是 git 的瘦包?

git - 在 Git 中存储生成的文件

git - 使用指定仓库中的 Git 分支动态填充 Jenkins Choice 参数

git - 在我的本地计算机上的两个不同位置有一个存储库的两个不同分支

GIT - checkout 到分支名称以 '<' 符号开头