Migration from Perforce to Git

Migrating Perforce to Git (GitHub) using GitFusion

Posted by Daniel Viorreta on August 24, 2015

Motivation

After almost ten years using Perforce in our company I have decided to move to Git. You can find a lot of posts about the advantages of using Git over other version control system (VCS). In my opinion, the most important advantage is that Git is becoming the default VCS.

Git Fusion

Perforce launched a very nice tool called Git Fusion. With Git Fusion you can work with your Git client without knowing that there is a Perforce server behind it. When a Git user pushes a change in the repo, GitFusion translates those Git changes into Perforce changes and submits them to the Perforce depot. And when a Perforce user submits a change to the Perforce depot Git Fusion translates those changes to Git depot.

Git Fusion is a powerfull tool that allows you keep using Perforce through it. But, as I only used it to move to Git, I just set the configuration that I needed.

My Perforce server was an old machine in our datacenter with RedHat 4 and Git Fusion was only available from RedHat 5. So, I installed a new machine in Amazon Web Services with the rpms of Git Fusion.

Once GitFusion is configured, you will find a new Perforce user called git-fusion-user . A new Perforce depot in //.git-fusion will be automatically created too.

I set my user adding a new file in //.git-fusion/users/daniel.viorreta/keys/keymac with my ssh public key. Then, I created a file like this //.git-fusion/repos/myrepo/p4gf_config for each repo that I wanted to migrate. As I used peforce streams my file looks like this:

[@repo]
description = Repo for MyRepo

[master]
git-branch-name = master
stream = //myrepo/mainline
original-view = //myrepo/mainline/... ...

[myfeature]
git-branch-name = feature/myfeature
stream = //myrepo/myfeature
original-view = //myrepo/myfeature/... ...
To clone the Git repo you can do it like a normal Git repo with git clone:
git clone git@git.gitfusion.zzivi.com:myrepo
Notice that the first time that you clone the repo Git Fusion will translate all the changes to Git repo, so it can take several minutes or hours depending on the size of your repo.

GitHub

Once that I had Git Fusion running I wanted to move my Git repo to GitHub. So I cloned my Git Fusion repo with the bare option. After creating a new empty repo in GitHub, I pushed my changes to the new repo adding a new remote to my Git configuration:

git clone git@git.gitfusion.zzivi.com:myrepo --bare  #clone repo from Git Fusion
git remote add github git@github.com:zzivi/myrepo.git # add github remote
git push github --mirror # push changes to github

Finally I removed the write permissions in the Perforce depot and started the new challenge of using Git!!