8

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?

1
  • Does the repo have any "releases"? Often you can download a zip file with the code for a specific release. Commented Aug 14, 2021 at 18:30

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The tarball download seems to be the best answer, and I can confirm that it works. For other users with the same problem, I will note that the tarball extracts the fileset into an ad-hoc folder named {repo}-{branch}/, so you'll have to move the repo files from that folder into the current folder manually. Still, this is likely as close as it's possible to get.
4

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.

Comments

4

You can just download it.

wget https://github.com/OrgName/RepoName/archive/refs/heads/branchname.zip

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.