创建一个新的 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 pull
、git pull --all
、git fetch
、git 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/