Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search remote repository for file names/contents

Tags:

git

Is it possible to search a remote repository for a file without having cloned it locally? Given for example the clone URL for this project, could I search the master branch for a file with a particular name? A file that contains a certain string?

git-ls-remote seems like it is kind of close to what I want, but combining it with git-ls-files or git-grep doesn't work (SO post showing how to use these for the same task on a local instance of a repository)

git ls-remote https://github.com/Vincit/objection.js.git ls-files '*/mixin.js'

just returns to the command prompt without printing any output at all, errors or otherwise.

like image 802
1252748 Avatar asked Oct 21 '25 15:10

1252748


1 Answers

Is it possible to search a remote repository for a file without having cloned it locally?

The short answer currently is "No".

Whilst ls-remote might look promising it only lists references, not files.

You also can't combine git commands in the way that you are attempting (unless the commands involved specifically support such combinations).

In addition to only working on refs, the reason the attempt to combine ls-remote with ls-files returns nothing is that the ls-files entry on the command line is interpreted by the ls-remote command as limiting output to only return refs that match "ls-files" (or "*/mixin.js").

There are none, so you get no output.

If you are concerned about the size of the repository you need to clone in order to do your searches locally and are only interested in the latest revision of the repo and are not concerned with files that may have existed in the history but are no longer present etc, you can of course limit clone to the most current revision, to avoid cloning the complete repo and history, using the --depth param e.g.:

git clone --depth=1 https://github.com/Vincit/objection.js.git

This doesn't avoid having to clone, but it does reduce the amount of work/time involved in doing so.

like image 71
Deltics Avatar answered Oct 23 '25 08:10

Deltics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!