26

Is there a way to download the contents of a git repo from the Unix command line that doesn't pull down everything in the .git directory? I just want the latest version of the repo directories and files, not all the diffs.

Also, is it possible to accomplish this without using a git command (perhaps with wget or curl, for example)?

Thanks.

Jim
  • 13,430
  • 26
  • 104
  • 155
  • Yes it is possible with a `git` command: http://stackoverflow.com/questions/1209999/using-git-to-get-just-the-latest-revision. I don't know what the git internal structure is, but I seriously doubt wget or curl would be useful. – CompuChip Dec 17 '13 at 21:48
  • What do you count as "the contents of a git repo"? The commit history that leads to the current version is part of this being a repository. Downloading the latest version is like downloading the latest release ZIP: No history, just the files. If there is no release, `git archive` should help, see http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export – Sven Dec 17 '13 at 22:10
  • 15
    @random: I really hate it when people get trigger happy with rejecting questions that would help so many people. Yes it's a perfectly valid question. Programming in the real world is more than just typing a+b – Bernard Feb 20 '14 at 02:38

4 Answers4

25

github has a link to download a .zip archive of the repo, so try using

wget https://github.com/[user]/[repo]/archive/[branch].zip

with [user], [repo], and [branch] replaced with the appropriate fields.

intropedro
  • 2,804
  • 1
  • 24
  • 25
randomusername
  • 7,927
  • 23
  • 50
  • Through the API, you could get a tarball instead of a zipball as well. [article](https://help.github.com/articles/downloading-files-from-the-command-line) [API reference](http://developer.github.com/v3/repos/contents/#get-archive-link) – Charlie Dec 17 '13 at 21:59
  • @Charlie Very true, but the OP asked for a solution with `wget` so that's what I gave them. – randomusername Dec 17 '13 at 22:00
11

As far as I know, the closest thing you can do is to do a git clone --depth=1 (to avoid retrieving more information from the server than you need for the latest version) and then delete the .git directory afterwards. As far as git is concerned, the .git directory is the repo; the checked-out files are just there for your convenience. :)

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • couldn't you use the git protocol directly to clone stuff without downloading the .git thing in the first place?? – Rainb Jun 25 '20 at 17:12
2

2nd part : You can try the username and repo name substituted correctly

wget http://github.com/[username]/[repo]/archive/master.zip
sujithvm
  • 2,351
  • 3
  • 15
  • 16
1

Nowadays* github even supports direct tar.gz download.

Therefore the following works nicely

curl -L http://github.com/[username]/[repo]/archive/[branch].tar.gz | tar zxf -

Note, the -L option in curl is important since that URL has a lot of 302 Redirect HTTP replies before giving out the content. wget automatically follows them, whereas curl does not.

[*] 7 years later ;-)

Steve Schnepp
  • 4,620
  • 5
  • 39
  • 54