git-p4
Import and submit changes between Git and Perforce
TLDR
Clone a Perforce depot into a new Git repository
Sync changes from Perforce into the current Git repository
Rebase local commits on top of the latest Perforce changes
Submit Git changes back to Perforce
Clone the full Perforce history instead of only the latest changelist
SYNOPSIS
git p4 command [--git-dir=<dir>] [options] [p4-options] [depot-path...]
Common commands: clone, sync, submit, rebase
PARAMETERS
clone
Clone Perforce depot into new Git repo with full history
sync
Fetch latest Perforce changes into existing Git repo
fetch
Synonym for sync; fetch P4 changes
submit
Submit Git commits back to Perforce interactively
rebase
Rebase current branch onto latest P4 sync
rollback
Abort/rollback last submit or sync
--git-dir=
Set Git repository directory
--bare
Treat Git repo as bare (no working tree)
--use-client-spec
Use P4 client spec views for paths
--detect-branches
Auto-detect and import P4 branches
--branch=
Sync/submit to specific Git branch
--destination=
Clone target directory (clone only)
--verbose
Enable detailed logging
--quiet
Suppress non-essential output
--max-changes=
Limit changes to import (sync/clone)
--changes=
Specific P4 changelist range
--user=
P4 username
--client=
P4 client spec name
--host=
P4 server host
--port=
P4 server port
--password=
P4 password
--keep-trailing-slash
Preserve trailing slashes in paths
--use-view
Use P4 client view mapping
-i
Interactive mode for submit
--dry-run
Preview submit without changes (submit)
DESCRIPTION
git-p4 is a Perl script included with Git for synchronizing repositories between Git and Perforce (P4). It enables importing full Perforce depot history into Git via git p4 clone, incremental updates with git p4 sync, and pushing changes back using git p4 submit.
Ideal for migrations from Perforce to Git or hybrid workflows. It leverages the p4 command-line client to fetch changes, maps Perforce paths to Git refs/branches, and uses git fast-import for efficiency. Supports branch detection, client specs, and verbose logging.
Limitations include slower performance on massive histories and imperfect handling of Perforce streams or exclusive locks. Commonly used in enterprises transitioning VCS or maintaining dual-repo setups. Requires P4 environment variables or client config.
CAVEATS
Requires p4 client in PATH and server access. Slow on large repos (>100k CLs). No native support for P4 streams/swarm. Exclusive files need manual handling. CRLF handling mismatches possible.
P4 SETUP
Set P4PORT, P4USER, P4CLIENT env vars or use options. Client View must map depot paths.
BRANCH MAPPING
P4 paths like //depot/proj/branch/... map to Git refs/heads/branch. Use --detect-branches for auto-import.
POST-SUBMIT WORKFLOW
After git p4 submit, run git p4 rebase to update local branch from P4.
HISTORY
Added in Git 1.6.0 (2008), developed by Google engineers (e.g., Richard Levitte) for Android codebase sync. Evolved with contributions; now mature but semi-maintained in Git core.
SEE ALSO
git(1), p4(1), git-fast-import(1), p4client(1)


