'How to git cat-file on a remote without having to clone first?

I'm trying to use git to read a file content on a remote without having to first clone the repository (kind of like git cat-file but from the remote).

For more context on the final goal. There's many repos out there exposing bash scripts we can curl and run locally. For example

bash -c "$(curl -fsSL raw.github.com/sboudrias/dotfiles/master/bin/dotfiles)"

This works for open source repo on Github since they're public. But this wouldn't work for either private repos or self-hosted gitlab instances.

Since git SSH authentication is already setup, I'm hoping to find a way to get the content of a file on a remote to run it before the user downloaded a whole clone.



Solution 1:[1]

This is not possible. git commands work within the context of a repository; they don't accept repositories as arguments. You have to have a local copy of the repository, and operate the git cat-file within that repository to get the file contents with that tool.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hefeweizen