Git: Interoperability and Collaboration
Git can import from and export to other version control systems, collaborate via email-based patch workflows, and export data in portable formats. This covers the bridging and collaboration commands: SVN and Perforce interop, email-based patch workflows, fast import/export for bulk data transfer, and the remaining commands from git help --all.
Commands Covered
git svn · git p4 · git cvsimport · git cvsexportcommit · git archimport · git send-email · git imap-send · git request-pull · git quiltimport · git fast-export · git fast-import
git svn
Bidirectional bridge between Git and Subversion. Lets you use Git locally while the "source of truth" remains a Subversion repository. Useful when a team hasn't migrated to Git yet.
# Clone a Subversion repository into Git $ git svn clone http://svn.example.com/project/trunk project # --stdlayout if the SVN repo has standard trunk/branches/tags structure: $ git svn clone --stdlayout http://svn.example.com/project project # Clone only recent history (faster for large repos) $ git svn clone -r 5000:HEAD http://svn.example.com/project/trunk project # Fetch new commits from SVN into Git $ git svn fetch $ git svn rebase # fetch + rebase local commits on top # Push Git commits to SVN (like git push — but to SVN) $ git svn dcommit # Show SVN revision information in git log $ git svn log $ git log --show-notes=* # shows svn-remote info # Find the SVN revision for a Git commit $ git svn find-rev HEAD $ git svn find-rev r1234 # find the Git commit for SVN rev 1234 # Create a Git branch from an SVN branch $ git svn branch feature-x # Create an SVN tag $ git svn tag v1.0.0 # Full migration — permanently move an SVN repo to Git $ git svn clone --stdlayout http://svn.example.com/project myrepo $ cd myrepo $ git remote add origin https://github.com/user/myrepo.git $ git push -u origin --all $ git push origin --tags
git p4
Import from and submit to Perforce (p4) repositories. Requires the p4 Perforce client to be installed.
# Clone a Perforce depot into Git $ git p4 clone //depot/main@all # Sync new changes from Perforce into Git $ git p4 sync # Submit Git commits back to Perforce $ git p4 submit # Clone only recent changelists $ git p4 clone //depot/main@12345,#head # Rebase on top of new Perforce changes $ git p4 rebase # Show pending submissions $ git p4 submit --dry-run
CVS Interoperability
# Import a CVS repository into Git $ git cvsimport -C my-git-repo :pserver:user@host:/cvsroot/module # Export a single Git commit to a CVS checkout $ git cvsexportcommit -v abc1234 # Emulate a CVS server (allows CVS clients to access a Git repo) $ git cvsserver # Configure via git config (experimental, rarely used today)
git archimport
# Import a GNU Arch repository into Git $ git archimport user@example.com--my-archive/project--main # GNU Arch (tla) was an early distributed VCS; rarely encountered today
Email-Based Patch Workflow
Before GitHub, patches were shared via email — you'd format a commit as a patch file and email it to a project's mailing list. The maintainer would review and apply it. This is still the workflow for the Linux kernel, Git itself, and many other projects.
git send-email
# Configure git send-email to use your mail server
$ git config --global sendemail.smtpServer smtp.gmail.com
$ git config --global sendemail.smtpServerPort 587
$ git config --global sendemail.smtpEncryption tls
$ git config --global sendemail.smtpUser you@gmail.com
# Send the last commit as a patch to a mailing list
$ git format-patch -1 -o /tmp/patches/
$ git send-email /tmp/patches/0001-Fix-login-bug.patch \
--to=project-patches@lists.example.com
# Send patches for commits on current branch not in main
$ git send-email --to=patches@example.com main
# Review what would be sent (dry run)
$ git send-email --dry-run --to=patches@example.com main
# Send with a cover letter (series of patches)
$ git format-patch --cover-letter --annotate -o /tmp/patches main
# Edit the cover letter, then:
$ git send-email /tmp/patches/
# Reply to an existing thread (for revised patches)
$ git send-email --in-reply-to="Message-ID@example.com" \
0001-v2-fix.patch
git imap-send
# Send patches directly to an IMAP drafts folder # (useful when SMTP is blocked but IMAP works) $ git config --global imap.host imap.gmail.com $ git config --global imap.user you@gmail.com $ git config --global imap.folder "[Gmail]/Drafts" $ git format-patch --stdout main | git imap-send # Patches appear as draft emails — review and send manually
git request-pull
# Generate a summary of pending changes for a maintainer $ git request-pull v1.0 https://github.com/your/fork.git main # Output (copy into an email): # The following changes since commit abc1234...: # # commit message (date) (abc1234) # # are available in the Git repository at: # https://github.com/your/fork.git main # # Jason Smith (3): # Fix login bug # Add search feature # Update documentation # # ...diff stats...
git quiltimport
# Apply a Quilt patch series as Git commits $ git quiltimport # Quilt is a patch management system that organizes patches in a series. # Common in Linux distribution packaging workflows. # Import patches from a specific directory $ git quiltimport --patches /path/to/patches/
git fast-export and git fast-import
These commands serialize and deserialize Git history in a text-based "fast-import stream" format. Used for migrating between VCS systems, filtering repositories, and bulk data operations.
git fast-export
# Export all history to fast-import format $ git fast-export --all > repo.fi # Export a specific branch $ git fast-export main > main.fi # Export with signed tags (verifiable) $ git fast-export --signed-tags=strip --all > repo.fi # Export only commits not in another repo (for incremental transfer) $ git fast-export main ^old-main > incremental.fi # Export to a file for piping to fast-import $ git fast-export HEAD | gzip > repo.fi.gz
git fast-import
# Import a fast-import stream into the current repo $ git fast-import < repo.fi # Import compressed stream $ zcat repo.fi.gz | git fast-import # Import with statistics $ git fast-import --stats < repo.fi # Force reference updates $ git fast-import --force < repo.fi # Typical VCS migration workflow: # 1. Export from old VCS to fast-import format (use conversion tool) $ svn-to-git-migrator > repo.fi # 2. Create a new Git repo $ mkdir new-git-repo && cd new-git-repo && git init # 3. Import $ git fast-import < /path/to/repo.fi $ git checkout HEAD
Remaining Commands Reference
| Command | What it does |
|---|---|
git citool | Graphical alternative to git commit (tcl/tk GUI) |
git gitk | Graphical repository browser (tcl/tk) |
git gui | Graphical interface for staging and committing |
git gitweb | Web-based Git repository viewer (CGI) |
git instaweb | Instantly browse a repo with gitweb in a browser: git instaweb --httpd=webrick |
git apply | Apply a patch to files and/or to the index (non-mailbox format; compare: git am handles mailbox patches) |
git merge-file | Three-way merge of files: git merge-file mine base theirs |
git merge-index | Run a merge helper for files that need merging in the index |
git mktag | Create a tag object with extra validation from stdin |
git mktree | Build a tree object from ls-tree formatted input |
git name-rev | Find symbolic names for commits: git name-rev abc1234 |
git cherry | Find commits not yet applied to upstream: git cherry main |
git diff-files | Compare working tree to index (low-level git diff) |
git diff-index | Compare index to a tree object |
git diff-tree | Compare two tree objects |
git diff-pairs | Compare specific blob pairs |
git ls-remote | List refs in a remote (covered in Remotes article) |
git merge-base | Find common ancestor: git merge-base main feature |
git patch-id | Compute a unique ID for a patch (content-based, ignores commit SHA) |
git stripspace | Remove trailing whitespace and normalize blank lines |
git column | Display data in columns (used internally by some commands) |
git var | Show Git logical variables: git var GIT_AUTHOR_IDENT |
git credential | Retrieve and store credentials via the credential helper |
git check-ref-format | Validate a ref name: git check-ref-format refs/heads/my-branch |
git fmt-merge-msg | Generate a merge commit message from merge heads |
git unpack-file | Create a temp file with a blob's content for external processing |
git pack-redundant | Find pack files that can be deleted (all their objects exist in other packs) |
git get-tar-commit-id | Extract the commit ID from a git archive tarball |
git replay | EXPERIMENTAL: replay commits on a new base in bare repos |
git sh-i18n | Git's i18n setup code for shell scripts (internal) |
git sh-setup | Common setup code used by Git's own shell scripts (internal) |
git lfs | Git Large File Storage — stores large files (binaries, media) separately from repo history (requires git-lfs extension) |
git jump | Jump to next diff, merge conflict, or grep match in your editor (requires setup) |
dispelled