Progress:
TIER 2 · MODULE 03· Intermediate

git fast-import

How most VCS-import tools (svn, hg, bzr) get into Git.

🎯 What & why

git fast-import consumes the stream produced by fast-export (or by hand-rolled importers from Subversion, Mercurial, Bazaar, Perforce, etc.) and builds blobs, trees, commits, tags, and refs directly into the target repo. It is the standard backend for any "import history into Git" tool.

🧠 Mental model

Heavy writer. It writes objects straight into a single packfile under .git/objects/pack/ and updates refs at the end. The working tree and index are untouched; this is a backend tool.

🛠️ Synopsis

git fast-import [--date-format=<fmt>] [--done] [--force] [--max-pack-size=<n>]
                [--big-file-threshold=<n>] [--depth=<n>] [--active-branches=<n>]
                [--export-marks=<file>] [--import-marks=<file>] [--import-marks-if-exists=<file>]
                [--[no-]relative-marks] [--cat-blob-fd=<fd>] [--done] [--quiet] [--stats]
                [--allow-unsafe-features]

🎚️ Switches & options

FlagWhat it does
--date-format=<fmt>raw, raw-permissive, rfc2822, or now. Set this to match what your importer emits or every commit date will be wrong.
--max-pack-size=<n>Roll over to a new packfile after n bytes (e.g. 1g). Useful for huge imports to keep packs manageable.
--depth=<n>Maximum delta chain depth in the produced pack. Default 50; raise for better compression at the cost of access time.
--active-branches=<n>How many branches fast-import keeps trees in memory for at once. Bump this for imports that touch many refs concurrently.
--export-marks=<file>Write the mark->SHA map after import. Pair with --import-marks for resumable / incremental imports.
--quietSuppress the periodic progress output. Use it in pipelines; do not use it interactively or you will think it hung.
--statsPrint packfile and memory statistics at the end. Always read these on a real import; they tell you if --depth and --active-branches were sane.

💡 Use cases

🧪 Examples

Pipe from fast-export
$ git -C src fast-export --all \
  | git -C dst fast-import --quiet --stats
Import a Mercurial repo
$ git init hg-mirror && cd hg-mirror
$ hg-fast-export.sh -r /path/to/hg-repo \
  | git fast-import --quiet --stats --export-marks=../hg.marks
Resumable import
$ git fast-import \
  --import-marks-if-exists=marks \
  --export-marks=marks \
  --max-pack-size=2g \
  < stream
Tune for a huge import
$ git fast-import \
  --depth=100 \
  --active-branches=200 \
  --max-pack-size=4g \
  --stats < big.stream

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.