I am placing this information here in case it saves someone else two days of web searching. These steps cover how to do it on Windows and thus have several extra steps that are not needed for Linux and macOS users.
- Perforce installed (with the p4 command line tools).
- Git installed: https://git-scm.com/download/win
- Python installed: https://www.microsoft.com/store/productId/9PJPW5LDXLZ5
It is assumed you have Perforce set up and authenticated so the p4 command line tool works. It is also assumed you have a remote Git repository like BitBucket also authenticated. I won’t cover those details.
Test the “git p4” command, and fix if needed.
From a command prompt, type “git p4” and see if it works. This relies on a python script called “get-p4” that may need to be edited to work with your version of Python. If you see this:
C:\>git p4 fatal: 'p4' appears to be a git command, but we were not able to execute it. Maybe git-p4 is broken?
…you will need to edit the file and update the first line to change the reference to “python2” to just be “python”. The file is located here:
Change the first line:
…to just be:
The original is apparently designed to run only on systems where the python executable is called “python2”.
Step 1 – Clone Perforce in to a local Git repository
Create a directory that will hold your Perforce depot directories, and change in to it:
md FromPerforce cd FromPerforce
Run the following command (where “xxx” is one of your Perforce depots — such as //depot or //Users or whatever you have). The @all will clone all revisions, and –import-labels is supposed to bring down all tags (this doesn’t seem to work for me):
git p4 clone --import-labels //XXX@all
When finished, you now have a subdirectory that is a local Git repository of all those Perforce files, including version history and commit comments.
Change in to this directory for the next step:
Step 2 – Create a fresh Git repository on BitBucket (or whever)
If you do not already have a Git repository on your remote server (BitBucket in this example), create one. You will need to know the URL of this repository, which is something like:
In BitBucket, you get this from the Clone button (it will populate a box with a git clone command line, and you can copy the URL from there).
Step 3 – Pull down the Git repository and rebase, and push the new stuff
git remote add origin https://firstname.lastname@example.org/accountname/XXX.git git pull origin master --rebase git push -u origin --all
(You can use “git remove remote origin” if you need to try this again, due to a type in the URL or something.)
Once that is done, you should be able to see all those Perforce files and their history in BitBucket.
Thanks for this, keep up the great work!
did you end up here from a search?