Getting a file from a repo through curl is not a feature of git
alone, it is a feature of web based git servers, like github
, gitlab
, or gogs
.
These servers generally allow you to browse to any file you want within the repo.
For example : on the gitub mirror of the git repo, you can click your way to the checkout.c
file :
https://github.com/git/git/blob/master/builtin/checkout.c
and then click on the [Raw]
button :
https://raw.githubusercontent.com/git/git/master/builtin/checkout.c
That's a url you can also access using curl
.
As it indicates, the above url targets the master
branch (which can evolve in time), you can find a way to target a commit identified by its fixed sha1
:
https://raw.githubusercontent.com/git/git/385c171a018f2747b329bcfa6be8eda1709e5abd/builtin/checkout.c
Browse on your own server to find out how urls are built.