blindside044
blindside044

Reputation: 456

git command to download branch files without repo?

I'm looking for something equivalent to manually going to a github repo and downloading a branch in a zip file without downloading the history (though it can just download the files without the zip file).

I've found git clone --depth 1 -b <branch> <repo_url> but I don't want to create a new repo on the local machine, I just want the files. I'm thinking using wget and unzip is a better option, but I'm not super familiar with git so I want to make sure I'm not missing anything first. Thank you.

Upvotes: 1

Views: 802

Answers (1)

bk2204
bk2204

Reputation: 76409

Git provides a couple of ways to do this, and GitHub provides some different ways.

If you're working just with plain Git, you can do a shallow clone and then delete the .git directory, or you can do a shallow (and possibly bare) clone and then create an archive with git archive. Both of those create a repository, but they are the most lightweight way using plain Git that works almost everywhere.

If you're using an SSH remote, you can try git archive --remote. Not all servers support this, and notably GitHub does not. It also does not work over HTTPS at all.

If you want a solution specific to GitHub, you can use the REST API to download an archive. You can specify an arbitrary commit, tag, or tree. You will, however, need to configure your HTTP client to follow redirects and appropriately authenticate if the repository is private.

Upvotes: 2

Related Questions