3

I have a git repository (managed also in remote) how can I find the current remote full path to a file with a single command?

for example:

src/main/java/myfile.java

I wish to run a command

git ????? src/main/java/myfile.java

which will then return the remote url for this file

https://github.com/repo/bla/src/main/java/myfile.java

is there a way to achieve that? The motivation for that is that I want to immediately get this path so i can send the url to another developer so when he clicks the url it will open the file for him in browser (if this file is hosted in github for example) and I want a single command for that, not to go through the whole process of getting the github base uri and then concatenating the relative path of the file i wish for a single command which will do that work for me.

Jas
  • 14,493
  • 27
  • 97
  • 148
  • Possible duplicate: http://stackoverflow.com/questions/2466735/how-to-checkout-only-one-file-from-git-repository – Melebius Oct 20 '15 at 09:20

1 Answers1

3

There is no such command for the simple reason that a remote is not necessarily backed by a (publicly) viewable webserver.

In the simplest case, a remote repository is just a folder that you can access somewhere. That folder is neither accessible via the webbrowser nor can you actually access the files directly in there (since the data is packed into the Git object database).

It’s just a special case of GitHub and a few other online repository hosting services that they also allow viewing the repository contents via the browser.

That being said, if you know that the remote repository is on GitHub, you can of course parse the remote URL, extract the repository path, and concat the file path to it. You could then easily put that in a script that you can call.

poke
  • 369,085
  • 72
  • 557
  • 602