有没有办法在不实际克隆的情况下检查存储库是否存在远程分支?
Is there a way to check if a remote branch exists for a repository without actually cloning it?
我正在从 Gitlab 中的上游管道触发下游管道 CI。
我想检查下游仓库中是否有与上游分支同名的分支,但我不想克隆整个下游仓库只是为了做一个 git branch --list
什么的.
基本上,我正在寻找一个只检查远程存储库中是否存在分支的单行文件。
如有任何建议,我们将不胜感激。谢谢!
是的,有。您可以使用 git ls-remote
。例如,如果您想查看 Git 的存储库中的分支,您可以这样做:
$ git ls-remote https://github.com/git/git.git refs/heads/*
69a9c10c95e28df457e33b3c7400b16caf2e2962 refs/heads/main
e9d7761bb94f20acc98824275e317fa82436c25d refs/heads/maint
69a9c10c95e28df457e33b3c7400b16caf2e2962 refs/heads/master
a2b2bfdf31eaee062391d5f278d6dd93cf7a3e4c refs/heads/next
03adea34405149b89748ff7ea766e1c7f06430cd refs/heads/seen
510d42bf652ebc22ceb54ba76b4d9023320194fa refs/heads/todo
如果需要,您可以指定refs/heads/main
,例如,查看是否有任何输出。这个命令在存储库之外工作得很好。您可以查看手册页以获取更多选项。
我正在从 Gitlab 中的上游管道触发下游管道 CI。
我想检查下游仓库中是否有与上游分支同名的分支,但我不想克隆整个下游仓库只是为了做一个 git branch --list
什么的.
基本上,我正在寻找一个只检查远程存储库中是否存在分支的单行文件。
如有任何建议,我们将不胜感激。谢谢!
是的,有。您可以使用 git ls-remote
。例如,如果您想查看 Git 的存储库中的分支,您可以这样做:
$ git ls-remote https://github.com/git/git.git refs/heads/*
69a9c10c95e28df457e33b3c7400b16caf2e2962 refs/heads/main
e9d7761bb94f20acc98824275e317fa82436c25d refs/heads/maint
69a9c10c95e28df457e33b3c7400b16caf2e2962 refs/heads/master
a2b2bfdf31eaee062391d5f278d6dd93cf7a3e4c refs/heads/next
03adea34405149b89748ff7ea766e1c7f06430cd refs/heads/seen
510d42bf652ebc22ceb54ba76b4d9023320194fa refs/heads/todo
如果需要,您可以指定refs/heads/main
,例如,查看是否有任何输出。这个命令在存储库之外工作得很好。您可以查看手册页以获取更多选项。