7

when I am running git pull or git fetch, I obviously retrieve both history and files. For huge projects, that takes very much time. I wonder how this process could be sped up, as for some projects I am only interested in the source code and not in the history. Is there a way to tell git that I only want to fetch the current snapshot of the files and not the whole history as well?

Max Beikirch
  • 2,053
  • 5
  • 25
  • 36
  • 1
    To the best of my knowledge, this isn't possible. Actually it's not what version control is all about. – AlexE Apr 15 '13 at 08:55
  • Git 1.9/2.0 (Q1 2014) will be much more efficient with shallow cloning: http://stackoverflow.com/a/21217267/6309 and http://stackoverflow.com/a/21217326/6309 – VonC Jan 19 '14 at 13:28

3 Answers3

17

You probably want to look at the --depth option in git clone--called a "shallow clone". In particular, you probably want:

git clone --depth=1 <url>

If the project is on GitHub, you can always use the download links from there. Note, there are some catches to using a shallow clone:

Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.

But that sounds like something you can live with.

Also, as positron pointed out, you can do this with git archive as well.

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
4

You can use a shallow clone:

git clone --depth=1 git://url/of/repo

However you won't be able to commit/push changes made in a shallow clone.

Schnouki
  • 7,527
  • 3
  • 33
  • 38
4

If there is a webview like gitweb or cgit, you can very well take a snapshot. But I don't think fetch of the code alone is possible. Because fetch is working on your git objects and not the code.

git archive --format=tar --remote=gitolite@server:repo.git HEAD | bzip2 > repo-snapshot.tar.bz2
positron
  • 1,652
  • 1
  • 11
  • 14