Search code examples
gitlibgit2

Is it possible to do `git clone --depth=1 <repository>` with libgit2?


I want to do a quick clone without getting all the .git history. Is this possible to do with libgit2?

I found this issue but I am not sure if this sparse checkout they reference is

same as running git clone --depth=1 https://github.com/libgit2/libgit2.


Solution

  • This is now possible! The libgit2 git_clone function takes git_clone_options as an argument. One of the members of that struct is git_fetch_options which takes a depth parameter.

    Note that to mimic git clone --depth=1 https://github.com/libgit2/libgit2 you will also need to fetch only the history for a single branch. This is achieved by passing your own callback via remote_cb.