There exists a public repository on GitHub. I have a terminal open to an empty directory on my own machine, and I would like to fill that directory with the set of files represented by a particular branch of this repository.
All I want is the fileset that constitutes the latest commit to the given branch. I don't need any history or revision metadata. It would be a waste of bandwidth, computation, and storage to git clone the repo or otherwise create a Git repository locally. It seems intuitive that there would be a command for me to download the set of files:
$ git {something} https://github.com/OrgName/RepoName.git branchname
to copy these files into the current directory. I've been looking for hours, and I can find nothing. There's too much "git clone" noise to every web search I've tried.
Is this possible, and how? If it is possible, can it be done without authenticating to GitHub?
There are a couple ways you can go about getting a single revision.
First, on GitHub, there are API endpoints for downloading a tarball or a zip file of a particular revision. They can be downloaded using curl, and require authentication only if the repository is private.
If the repository has release assets that contain a specific tarball or other archive that you want to download, you can first look up the release and then download the asset you want. This is helpful if releases contain generated files or other things that won't be in the autogenerated tarballs.
You can also choose to do a shallow clone. That is, you can pass the --depth 1 option to git clone to download the data for only one revision, and you can specify a branch with the -b BRANCH option. That will end up with a .git directory, which you can delete if you want, or you can use git archive HEAD to generate an archive from that.
I think there is only the following solution:
git clone -b branchname --depth 1 --single-branch https://github.com/OrgName/RepoName.git \
&& rm -rf RepoName/.git/
It clones a single branch (-b branchname --single-branch), taking only the last commi (--depth = 1), the it removes then .git folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With