1<title>Import And Export</title>
2
3Fossil has the ability to import and export repositories from and to
4[http://git-scm.com/ | Git].  And since most other version control
5systems will also import/export from Git, that means that you can
6import/export a Fossil repository to most version control systems using
7Git as an intermediary.
8
9<h2>Git → Fossil</h2>
10
11To import a Git repository into Fossil, run commands like this:
12
13<blockquote><pre>
14cd git-repo
15git fast-export --all | fossil import --git new-repo.fossil
16</pre></blockquote>
17
18In other words, simply pipe the output of the "git fast-export" command
19into the "fossil import --git" command.  The 3rd argument to the "fossil import"
20command is the name of a new Fossil repository that is created to hold the Git
21content.
22
23The --git option is not actually required.  The git-fast-export file format
24is currently the only VCS interchange format that Fossil understands.  But
25future versions of Fossil might be enhanced to understand other VCS
26interchange formats, and so for compatibility, use of the
27--git option is recommended.
28
29<a id="fx_git"></a>
30Note that in new imports, Fossil defaults to using the email component of the
31Git <em>committer</em> (or <em>author</em> if <code>--use-author</code> is
32passed) to attribute check-ins in the imported repository. Alternatively, the
33[/help?cmd=import | <code>--attribute</code>] option can be passed to have all
34commits by a given committer attributed to a desired username. This will create
35and populate the new <code>fx_git</code> table in the repository database to
36maintain a record of correspondent usernames and email addresses that can be
37used in subsequent exports or incremental imports.
38
39<h2>Fossil → Git</h2>
40
41To convert a Fossil repository into a Git repository, run commands like
42this:
43
44<blockquote><pre>
45git init new-repo
46cd new-repo
47fossil export --git ../repo.fossil | git fast-import
48</pre></blockquote>
49
50In other words, create a new Git repository, then pipe the output from the
51"fossil export --git" command into the "git fast-import" command.
52
53Note that the "fossil export --git" command only exports the versioned files.
54Tickets and wiki and events are not exported, since Git does not understand
55those concepts.
56
57As with the "import" command, the --git option is not required
58since the git-fast-export file format is currently the only VCS interchange
59format that Fossil will generate.  However,
60future versions of Fossil might add the ability to generate other
61VCS interchange formats, and so for compatibility, the use of the --git
62option recommended.
63
64<h2>Mirror A Fossil Repository In Git</h2>
65
66Fossil version 2.9 and later supports a simple mechanism for
67doing a Git or
68[./mirrortogithub.md|GitHub mirror of a Fossil repository].
69See that separate document for details.  Fossil is self-hosting,
70but a [https://github.com/drhsqlite/fossil-mirror|GitHub mirror of Fossil]
71is available as a proof-of-concept.
72
73<h2>Bidirectional Synchronization</h2>
74Fossil also has the ability to synchronize with a Git repository via repeated
75imports and/or exports.  To do this, it uses marks files to store a record of
76artifacts which are known by both Git and Fossil to exist at a given point in
77time.
78
79To illustrate, consider the example of a remote Fossil repository that a
80user wants to import into a local Git repository.  First, the user would clone
81the remote repository and import it into a new Git repository:
82
83<blockquote><pre>
84fossil clone /path/to/remote/repo.fossil repo.fossil
85mkdir repo
86cd repo
87fossil open ../repo.fossil
88mkdir ../repo.git
89cd ../repo.git
90git init .
91fossil export --git --export-marks ../repo/fossil.marks  \
92       ../repo.fossil | git fast-import                  \
93       --export-marks=../repo/git.marks
94</pre></blockquote>
95
96Once the import has completed, the user would need to <tt>git checkout
97trunk</tt>.  At any point after this, new changes can be imported from the
98remote Fossil repository:
99
100<blockquote><pre>
101cd ../repo
102fossil pull
103cd ../repo.git
104fossil export --git --import-marks ../repo/fossil.marks  \
105       --export-marks ../repo/fossil.marks               \
106       ../repo.fossil | git fast-import                  \
107       --import-marks=../repo/git.marks                  \
108       --export-marks=../repo/git.marks
109</pre></blockquote>
110
111Changes in the Git repository can be exported to the Fossil repository and then
112pushed to the remote:
113
114<blockquote><pre>
115git fast-export --import-marks=../repo/git.marks                  \
116    --export-marks=../repo/git.marks --all | fossil import --git  \
117    --incremental --import-marks ../repo/fossil.marks             \
118    --export-marks ../repo/fossil.marks ../repo.fossil
119cd ../repo
120fossil push
121</pre></blockquote>
122