Skip to content

Commit e678884

Browse files
committed
samples: add how to simulate 'git clone --mirror'
1 parent 527b36f commit e678884

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/guides/101-samples/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ error = git_clone_into(repo, origin, &co_opts, "master");
131131

132132
([`git_clone_into`](http://libgit2.github.com/libgit2/#HEAD/group/clone/git_clone_into))
133133

134+
### Clone (Mirror)
135+
136+
```c
137+
git_repository *repo = NUL
138+
error = git_repository_init(&repo, "/tmp/…", true);
139+
/* Customize the repo */
140+
141+
/* Create an 'origin' remote with the mirror fetch refspec */
142+
git_remote *origin = NULL;
143+
error = git_remote_create_with_fetchspec(&origin, repo, "origin",
144+
"http://…", "+refs/*:refs/*");
145+
/* Customize the remote, set callbacks, etc. */
146+
147+
error = git_clone_into(repo, origin, NULL, NULL);
148+
/* Set remote.origin.mirror = true for compatibility with git-core */
149+
```
150+
151+
([`git_remote_create_with_fetchspec`](http://libgit2.github.com/libgit2/#HEAD/group/remote/git_remote_create_with_fetchspec),
152+
[`git_clone_into`](http://libgit2.github.com/libgit2/#HEAD/group/clone/git_clone_into)))
134153

135154
### Opening (Simple)
136155

0 commit comments

Comments
 (0)