检查git存储库是否存在 [英] Check that git repository exists

查看:495
本文介绍了检查git存储库是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在执行git clone操作之前检查git存储库是否存在?像git clone $ REMOTE_URL --dry-run?

我想实现快速检查方法,它会在克隆操作执行之前检查存在。我预计连接速度可能会变慢,并且存储库可能会超过1GB,所以我不想依赖于时间的大量操作,因为只需进行简单的验证。当验证通过时,克隆将在后台异步执行。



我发现这个 https://superuser.com/questions/227509/git-ping-check-if-remote-repository-exists ,但它在git存储库上下文后工作初始的克隆操作完成。

也许有一些git调用在没有git存储库上下文的情况下工作,并且如果目标存储库存在则返回一些数据 。

解决方案

您链接的答案完成您想要的功能。



尝试在没有存储库的文件夹中运行它:

  git ls-remote https:// github。 com / git / git 

它应该会显示远程引用,即使您没有使用 git init 或完成 git clone 添加本地存储库。



更多信息: https://www.kernel。 org / pub / software / scm / git / docs / git-ls-remote.html


Is there any way how to check whether git repository exist just before perform git clone action? Something like git clone $REMOTE_URL --dry-run?

I would like to implement fast checking method which will check existence before the clone action will be performed. I expect that connection might be slow and repository might be big even more than 1GB, so I don't want to rely on time extensive operation due to simple validation. The clone will be performed asynchronously in the background when validation passes.

I found this https://superuser.com/questions/227509/git-ping-check-if-remote-repository-exists but it works from git repository context after initial clone action is done.

Maybe there is some git call which works without git repository context and return "some data" if repository on destination exist or error if doesn't.

解决方案

The answer that you linked does what you want it to do.

Try running this in a folder without a repository in it:

git ls-remote https://github.com/git/git

It should show you the references on the remote, even though you haven't added a local repository with git init or done a git clone.

See more: https://www.kernel.org/pub/software/scm/git/docs/git-ls-remote.html

这篇关于检查git存储库是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆