4

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.

1252748
  • 14,597
  • 32
  • 109
  • 229

1 Answers1

1

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.

Deltics
  • 22,162
  • 2
  • 42
  • 70