【问题标题】:Is there a way to check if a remote branch exists for a repository without actually cloning it?有没有办法在不实际克隆的情况下检查存储库是否存在远程分支?
【发布时间】:2022-01-20 16:18:03
【问题描述】:

我正在从 Gitlab CI 中的上游管道触发下游管道。

我想检查下游 repo 中是否存在与上游分支同名的分支,但我不想克隆整个下游 repo 只是为了做一个git branch --list 或其他东西。

基本上,我正在寻找一个只检查远程存储库中是否存在分支的单行程序。

任何建议将不胜感激。谢谢!

【问题讨论】:

    标签: git github gitlab-ci


    【解决方案1】:

    是的,有。您可以使用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,并查看是否有任何输出,例如。这个命令在存储库之外工作得很好。您可以查看手册页了解更多选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      • 2020-02-24
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 2012-02-14
      相关资源
      最近更新 更多