Skip to content

git fast-import / fast-export — quick reference ​

Export ​

TaskCommand
Full repogit fast-export --all > repo.stream
Last N commitsgit fast-export HEAD~N..HEAD > repo.stream
Single branchgit fast-export --branches main > repo.stream
Path-filteredgit fast-export --path src/ --path docs/ main > repo.stream
With prefixgit fast-export --prefix=services/A/ --all > repo.stream
Anonymizedgit fast-export --anonymize --all > repo.stream
Show original IDsgit fast-export --show-original-ids --all > repo.stream
Incrementalgit fast-export --export-marks=marks --import-marks=marks --all

Import ​

TaskCommand
Into fresh repomkdir t && cd t && git init && git fast-import < stream && git reset --hard HEAD
Into existinggit fast-import < stream && git reset --hard HEAD
With marks trackinggit fast-import --export-marks=.git/marks --import-marks=.git/marks < stream
Over SSHssh host "cd /repo && git fast-import" < stream

Stream format ​

blob
mark :1
data <bytes>
<content>

commit refs/heads/main
mark :2
author Name <e> <ts> +0000
committer Name <e> <ts> +0000
data <bytes>
<message>
from :1
M 100644 :1 README.md

tag refs/tags/v1.0
mark :3
tagger Name <e> <ts> +0000
data <bytes>
<tag message>
from :2

done

File change commands inside commits ​

CmdModeAction
M 100644 :mark path644/755/120000/160000Add/modify file
D path—Delete file
C old new—Copy file
R old new—Rename file
deleteall—Clear entire tree

DevOps one-liners ​

bash
# Consolidate repos under prefixes
for repo in A B C; do git -C $repo fast-export --prefix=$repo/ --all; done | git fast-import

# Split one directory into its own repo
git fast-export --path=services/A --all > split.stream

# Pipe across hosts (anonymized)
ssh src "cd /repo && git fast-export --all --anonymize" | cd /debug && git init && git fast-import

# Generate synthetic 10-commit repo
for i in $(seq 10); do echo "blob"; echo "mark :$((i*2-1))"; echo "data 3"; echo "v$i"; echo "commit refs/heads/main"; echo "mark :$((i*2))"; echo "author T <t@t> $(($(date +%s)+i*100)) +0000"; echo "committer T <t@t> $(($(date +%s)+i*100)) +0000"; echo "data 3"; echo "v$i"; [ $i -eq 1 ] && echo "feature date-format=raw" || echo "from :$((i*2-2))"; echo "M 100644 :$((i*2-1)) f-$i.txt"; echo ""; done; echo "done" | git fast-import

Marks: incremental migration ​

# Phase 1
git -C src fast-export --export-marks=marks --all | git -C dst fast-import --export-marks=marks
# Phase 2 (days later)
git -C src fast-export --export-marks=marks-new --import-marks=marks --all | git -C dst fast-import --export-marks=marks --import-marks=marks-new

See also ​

  • docs/devops-workflows/git-fast-import-export.md — full guide with patterns
  • scripts/fast-import-manage.sh — automation wrapper

Git Master — Git Reference for Every Skill Level